Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 273 lines (227 sloc) 9.171 kb
e625baf @chobie inserted licence string to file.
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 +----------------------------------------------------------------------+
e625baf @chobie inserted licence string to file.
authored
17 */
18
798c4cf @chobie change license to PHP License from MIT.
authored
19
19b8b2d @chobie rename to Sundown.
authored
20 #include "php_sundown.h"
648445f @stealth35 fix serveral compile warnings
stealth35 authored
21 #include "ext/standard/info.h"
4610cfb @chobie PHPSkirt has started!
authored
22
648445f @stealth35 fix serveral compile warnings
stealth35 authored
23 extern void php_sundown_render_base_init(TSRMLS_D);
4b10a7e @chobie add Sundown\Buffer class.
authored
24 extern void php_sundown_render_html_init(TSRMLS_D);
6b9fe9b @chobie add Sundown\Render\HTML_TOC render.
authored
25 extern void php_sundown_render_html_toc_init(TSRMLS_D);
0db2010 @chobie added XHTML render class template
authored
26 extern void php_sundown_render_xhtml_init(TSRMLS_D);
4b10a7e @chobie add Sundown\Buffer class.
authored
27 extern void php_sundown_markdown_init(TSRMLS_D);
4610cfb @chobie PHPSkirt has started!
authored
28
4b10a7e @chobie add Sundown\Buffer class.
authored
29 zend_class_entry *sundown_class_entry;
783b6d0 @chobie following PHP Cording standards.
authored
30
4b10a7e @chobie add Sundown\Buffer class.
authored
31 void php_sundown_init(TSRMLS_D);
174598e @chobie added Upskirt::to_toc().
authored
32
19b8b2d @chobie rename to Sundown.
authored
33 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown__construct, 0, 0, 2)
95c5519 @chobie modify methods signature.
authored
34 ZEND_ARG_INFO(0, data)
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
35 ZEND_ARG_ARRAY_INFO(0, extensions, 0)
95c5519 @chobie modify methods signature.
authored
36 ZEND_END_ARG_INFO()
37
e4f9933 @chobie add hasRenderFlag method
authored
38 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_has_extension, 0, 0, 1)
39 ZEND_ARG_INFO(0, name)
40 ZEND_END_ARG_INFO()
41
42 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_has_render_flag, 0, 0, 1)
43 ZEND_ARG_INFO(0, name)
44 ZEND_END_ARG_INFO()
45
19b8b2d @chobie rename to Sundown.
authored
46 static void sundown__render(SundownRendererType render_type, INTERNAL_FUNCTION_PARAMETERS)
4610cfb @chobie PHPSkirt has started!
authored
47 {
ca302a7 @chobie for now support custom method. but this will change soon.
authored
48 zval *object;
4610cfb @chobie PHPSkirt has started!
authored
49 struct buf input_buf, *output_buf;
17a74fd @chobie for now update sundown structure and prepare php-sundown2.
authored
50 struct sd_callbacks sundown_render;
ca302a7 @chobie for now support custom method. but this will change soon.
authored
51 struct php_sundown_renderopt opt;
71ba79b @chobie update sundown and support Sondown\Render\HTML
authored
52 struct sd_markdown *markdown;
eb977d4 @chobie change exntension object to hash.
authored
53 unsigned int enabled_extensions = 0, render_flags = 0;
783b6d0 @chobie following PHP Cording standards.
authored
54 char *buffer;
55 int buffer_len = 0;
9a0bdc6 @chobie add config.w32 file.
authored
56 HashTable *table;
ca302a7 @chobie for now support custom method. but this will change soon.
authored
57
58 object = getThis();
19b8b2d @chobie rename to Sundown.
authored
59 buffer = Z_STRVAL_P(zend_read_property(sundown_class_entry, getThis(),"data",sizeof("data")-1, 0 TSRMLS_CC));
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
60 buffer_len = strlen(buffer);
4610cfb @chobie PHPSkirt has started!
authored
61
62 memset(&input_buf, 0x0, sizeof(struct buf));
63 input_buf.data = buffer;
64 input_buf.size = strlen(buffer);
65
66 output_buf = bufnew(128);
e625baf @chobie inserted licence string to file.
authored
67 bufgrow(output_buf, strlen(buffer) * 1.2f);
68
9273baa @chobie following K&R coding style and fix misunderstood zend_parameter_parse va...
authored
69 if (Z_TYPE_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC)) != IS_NULL) {
19b8b2d @chobie rename to Sundown.
authored
70 table = Z_ARRVAL_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC));
146d1ab @chobie fixed missunderstood extensions
authored
71 }
19b8b2d @chobie rename to Sundown.
authored
72 php_sundown__get_flags(table, &enabled_extensions, &render_flags);
174598e @chobie added Upskirt::to_toc().
authored
73
17a74fd @chobie for now update sundown structure and prepare php-sundown2.
authored
74 // setup render
174598e @chobie added Upskirt::to_toc().
authored
75 switch (render_type) {
19b8b2d @chobie rename to Sundown.
authored
76 case SUNDOWN_RENDER_HTML:
ca302a7 @chobie for now support custom method. but this will change soon.
authored
77 sdhtml_renderer(&sundown_render, &opt.html, render_flags);
95c5519 @chobie modify methods signature.
authored
78 break;
19b8b2d @chobie rename to Sundown.
authored
79 case SUNDOWN_RENDER_TOC:
ca302a7 @chobie for now support custom method. but this will change soon.
authored
80 sdhtml_toc_renderer(&sundown_render,&opt.html);
95c5519 @chobie modify methods signature.
authored
81 break;
82 default:
83 RETURN_FALSE;
174598e @chobie added Upskirt::to_toc().
authored
84 }
ca302a7 @chobie for now support custom method. but this will change soon.
authored
85 opt.self = object;
17a74fd @chobie for now update sundown structure and prepare php-sundown2.
authored
86
b2dd5e7 @chobie fixed #5 render extension does not work correctly
authored
87 markdown = sd_markdown_new(enabled_extensions, 16, &sundown_render, &opt);
71ba79b @chobie update sundown and support Sondown\Render\HTML
authored
88 sd_markdown_render(output_buf, input_buf.data, input_buf.size, markdown);
89 sd_markdown_free(markdown);
4610cfb @chobie PHPSkirt has started!
authored
90
19b8b2d @chobie rename to Sundown.
authored
91 if (Z_BVAL_P(zend_read_property(sundown_class_entry, getThis(),"enable_pants",sizeof("enable_pants")-1, 0 TSRMLS_CC))) {
146d1ab @chobie fixed missunderstood extensions
authored
92 struct buf *smart_buf = bufnew(128);
71ba79b @chobie update sundown and support Sondown\Render\HTML
authored
93 sdhtml_smartypants(smart_buf, output_buf->data,output_buf->size);
146d1ab @chobie fixed missunderstood extensions
authored
94 RETVAL_STRINGL(smart_buf->data, smart_buf->size,1);
95 bufrelease(smart_buf);
96 } else {
97 RETVAL_STRINGL(output_buf->data, output_buf->size,1);
98 }
4610cfb @chobie PHPSkirt has started!
authored
99 }
100
77af627 @chobie modified method comments
authored
101 /* {{{ proto string Sundonw::__construct(string $string [, array $extensions])
19b8b2d @chobie rename to Sundown.
authored
102 setup Sundown extension */
103 PHP_METHOD(sundown, __construct)
174598e @chobie added Upskirt::to_toc().
authored
104 {
df81b01 @chobie forget to init NULL
authored
105 zval *extensions = NULL,*c_extensions = NULL;
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
106 char *buffer;
107 int buffer_len = 0;
174598e @chobie added Upskirt::to_toc().
authored
108
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
109 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s|a",&buffer, &buffer_len, &extensions) == FAILURE) {
174598e @chobie added Upskirt::to_toc().
authored
110 return;
111 }
112
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
113 add_property_string_ex(getThis(),"data",sizeof("data"),buffer,1 TSRMLS_CC);
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
114
115 if (extensions == NULL) {
27706d0 @chobie fixed segv when extensions or render flags ommited
authored
116 MAKE_STD_ZVAL(c_extensions);
117 array_init(c_extensions);
fc210fa @chobie fixed #2. forgot to increment specified array's refcount
authored
118 } else {
46a92dc @chobie use ZVAL_ZVAL instead of retaining render_flags and extensions.
authored
119 ALLOC_INIT_ZVAL(c_extensions);
120 ZVAL_ZVAL(c_extensions,extensions,1,0);
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
121 }
46a92dc @chobie use ZVAL_ZVAL instead of retaining render_flags and extensions.
authored
122 add_property_zval_ex(getThis(),"extensions",sizeof("extensions"),c_extensions TSRMLS_CC);
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
123 }
124 /* }}} */
125
77af627 @chobie modified method comments
authored
126 /* {{{ proto void Sundonw::__destruct()
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
127 cleanup variables */
19b8b2d @chobie rename to Sundown.
authored
128 PHP_METHOD(sundown, __destruct)
f661c1e @chobie fix segumentation fault when specified unexpected 2nd parameter.
authored
129 {
130 zval *extensions;
131
19b8b2d @chobie rename to Sundown.
authored
132 extensions = zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC);
46a92dc @chobie use ZVAL_ZVAL instead of retaining render_flags and extensions.
authored
133 zval_ptr_dtor(&extensions);
174598e @chobie added Upskirt::to_toc().
authored
134 }
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
135 /* }}} */
136
90fc882 @chobie added Sundown::toHtml and Sundown::toToc methods. to_html and to_toc bec...
authored
137 /* {{{ proto string Sundonw::toHtml()
783b6d0 @chobie following PHP Cording standards.
authored
138 Returns converted HTML string */
90fc882 @chobie added Sundown::toHtml and Sundown::toToc methods. to_html and to_toc bec...
authored
139 PHP_METHOD(sundown, toHtml)
174598e @chobie added Upskirt::to_toc().
authored
140 {
19b8b2d @chobie rename to Sundown.
authored
141 sundown__render(SUNDOWN_RENDER_HTML,INTERNAL_FUNCTION_PARAM_PASSTHRU);
174598e @chobie added Upskirt::to_toc().
authored
142 }
783b6d0 @chobie following PHP Cording standards.
authored
143 /* }}} */
174598e @chobie added Upskirt::to_toc().
authored
144
77af627 @chobie modified method comments
authored
145 /* {{{ proto string Sundonw::__toString()
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
146 Returns converted HTML string */
19b8b2d @chobie rename to Sundown.
authored
147 PHP_METHOD(sundown, __toString)
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
148 {
19b8b2d @chobie rename to Sundown.
authored
149 sundown__render(SUNDOWN_RENDER_HTML,INTERNAL_FUNCTION_PARAM_PASSTHRU);
9346d75 @chobie oops sorry, Acutually i'll fix Upskirt signature.
authored
150 }
151 /* }}} */
152
90fc882 @chobie added Sundown::toHtml and Sundown::toToc methods. to_html and to_toc bec...
authored
153 /* {{{ proto string Sundonw::toToc()
783b6d0 @chobie following PHP Cording standards.
authored
154 Returns table of contents*/
90fc882 @chobie added Sundown::toHtml and Sundown::toToc methods. to_html and to_toc bec...
authored
155 PHP_METHOD(sundown, toToc)
174598e @chobie added Upskirt::to_toc().
authored
156 {
19b8b2d @chobie rename to Sundown.
authored
157 sundown__render(SUNDOWN_RENDER_TOC,INTERNAL_FUNCTION_PARAM_PASSTHRU);
174598e @chobie added Upskirt::to_toc().
authored
158 }
159
e4f9933 @chobie add hasRenderFlag method
authored
160
161 /* {{{ proto string Sundown::hasExtension(string $ext_name)
162 */
163 PHP_METHOD(sundown, hasExtension)
164 {
165 char *name;
166 int name_len = 0;
167 HashTable *table;
168
169
170 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
171 "s", &name, &name_len) == FAILURE) {
172 return;
173 }
174
175 if (Z_TYPE_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC)) != IS_NULL) {
176 table = Z_ARRVAL_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC));
177 RETVAL_BOOL(php_sundown_has_ext(table, name));
178 }
179 }
180
181 /* {{{ proto string Sundown::hasRenderFlag(string $ext_name)
182 */
183 PHP_METHOD(sundown, hasRenderFlag)
184 {
185 char *name;
186 int name_len = 0;
187 HashTable *table;
188
189 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
190 "s", &name, &name_len) == FAILURE) {
191 return;
192 }
193
194 if (Z_TYPE_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC)) != IS_NULL) {
195 table = Z_ARRVAL_P(zend_read_property(sundown_class_entry, getThis(),"extensions",sizeof("extensions")-1, 0 TSRMLS_CC));
196 RETVAL_BOOL(php_sundown_has_ext(table, name));
197 }
198 }
199
a3bfd79 @chobie function_entry declaration seems to be obsolete on php5.4. use instead o...
authored
200 static zend_function_entry php_sundown_methods[] = {
19b8b2d @chobie rename to Sundown.
authored
201 PHP_ME(sundown, __construct, arginfo_sundown__construct, ZEND_ACC_PUBLIC)
6f44ab6 @chobie adjust vertical lines
authored
202 PHP_ME(sundown, __destruct, NULL, ZEND_ACC_PUBLIC)
90fc882 @chobie added Sundown::toHtml and Sundown::toToc methods. to_html and to_toc bec...
authored
203 PHP_ME(sundown, toHtml, NULL, ZEND_ACC_PUBLIC)
204 PHP_ME(sundown, toToc, NULL, ZEND_ACC_PUBLIC)
6f44ab6 @chobie adjust vertical lines
authored
205 PHP_ME(sundown, __toString, NULL, ZEND_ACC_PUBLIC)
e4f9933 @chobie add hasRenderFlag method
authored
206 PHP_ME(sundown, hasExtension,arginfo_sundown_has_extension,ZEND_ACC_PUBLIC)
207 PHP_ME(sundown, hasRenderFlag,arginfo_sundown_has_render_flag,ZEND_ACC_PUBLIC)
90fc882 @chobie added Sundown::toHtml and Sundown::toToc methods. to_html and to_toc bec...
authored
208 /* to_html and to_toc methods are compatible with Redcarpet */
209 PHP_MALIAS(sundown, to_html, toHtml, NULL, ZEND_ACC_PUBLIC)
210 PHP_MALIAS(sundown, to_toc, toToc, NULL, ZEND_ACC_PUBLIC)
4610cfb @chobie PHPSkirt has started!
authored
211 {NULL, NULL, NULL}
212 };
783b6d0 @chobie following PHP Cording standards.
authored
213 /* }}} */
4610cfb @chobie PHPSkirt has started!
authored
214
215
19b8b2d @chobie rename to Sundown.
authored
216 PHP_MINIT_FUNCTION(sundown) {
217 php_sundown_init(TSRMLS_C);
c865de4 @chobie put stubs
authored
218 php_sundown_render_base_init(TSRMLS_C);
219 php_sundown_render_html_init(TSRMLS_C);
0db2010 @chobie added XHTML render class template
authored
220 php_sundown_render_xhtml_init(TSRMLS_C);
6b9fe9b @chobie add Sundown\Render\HTML_TOC render.
authored
221 php_sundown_render_html_toc_init(TSRMLS_C);
4b10a7e @chobie add Sundown\Buffer class.
authored
222 php_sundown_markdown_init(TSRMLS_C);
2f88fca @chobie fix something. add Markdown test case. we've just passed MarkdownTest_1....
authored
223
224 REGISTER_NS_STRING_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "HTML", "Sundown\\Render\\HTML", CONST_CS | CONST_PERSISTENT);
3132564 @chobie added constant Sundown\Render\LIST_ORDERED
authored
225 REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "LIST_ORDERED", 1, CONST_CS | CONST_PERSISTENT);
517619a @chobie fix #19 Autolink is broken for emails
authored
226 REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "MKDA_EMAIL", MKDA_EMAIL, CONST_CS | CONST_PERSISTENT);
227 REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME("Sundown","Render"), "MKDA_NORMAL", MKDA_NORMAL, CONST_CS | CONST_PERSISTENT);
4610cfb @chobie PHPSkirt has started!
authored
228 return SUCCESS;
229 }
230
783b6d0 @chobie following PHP Cording standards.
authored
231
19b8b2d @chobie rename to Sundown.
authored
232 PHP_MINFO_FUNCTION(sundown)
4610cfb @chobie PHPSkirt has started!
authored
233 {
af5f7b9 @chobie update MINFO
authored
234 php_printf("PHP Sundown Extension\n");
235 php_info_print_table_start();
236 php_info_print_table_row(2,"Sundown Support", "enabled");
e918a8e @chobie update sundown revision.
authored
237 php_info_print_table_row(2,"Sundown Version", "3361ebcd22089fe64860f96a7b6acaf18a55746e");
af5f7b9 @chobie update MINFO
authored
238 php_info_print_table_end();
4610cfb @chobie PHPSkirt has started!
authored
239 }
240
19b8b2d @chobie rename to Sundown.
authored
241 zend_module_entry sundown_module_entry = {
4610cfb @chobie PHPSkirt has started!
authored
242 #if ZEND_MODULE_API_NO >= 20010901
243 STANDARD_MODULE_HEADER,
244 #endif
19b8b2d @chobie rename to Sundown.
authored
245 "sundown",
17a74fd @chobie for now update sundown structure and prepare php-sundown2.
authored
246 NULL, /* Functions */
19b8b2d @chobie rename to Sundown.
authored
247 PHP_MINIT(sundown), /* MINIT */
4610cfb @chobie PHPSkirt has started!
authored
248 NULL, /* MSHUTDOWN */
249 NULL, /* RINIT */
250 NULL, /* RSHUTDOWN */
19b8b2d @chobie rename to Sundown.
authored
251 PHP_MINFO(sundown), /* MINFO */
4610cfb @chobie PHPSkirt has started!
authored
252 #if ZEND_MODULE_API_NO >= 20010901
19b8b2d @chobie rename to Sundown.
authored
253 PHP_SUNDOWN_EXTVER,
4610cfb @chobie PHPSkirt has started!
authored
254 #endif
255 STANDARD_MODULE_PROPERTIES
256 };
257
c865de4 @chobie put stubs
authored
258
19b8b2d @chobie rename to Sundown.
authored
259 void php_sundown_init(TSRMLS_D)
4610cfb @chobie PHPSkirt has started!
authored
260 {
261 zend_class_entry ce;
77af627 @chobie modified method comments
authored
262
19b8b2d @chobie rename to Sundown.
authored
263 INIT_CLASS_ENTRY(ce, "Sundown", php_sundown_methods);
264 sundown_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
265 zend_declare_property_null(sundown_class_entry, "extensions", sizeof("extensions")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
266 zend_declare_property_null(sundown_class_entry, "enable_pants", sizeof("enable_pants")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
4610cfb @chobie PHPSkirt has started!
authored
267 }
268
269
19b8b2d @chobie rename to Sundown.
authored
270 #ifdef COMPILE_DL_SUNDOWN
271 ZEND_GET_MODULE(sundown)
4610cfb @chobie PHPSkirt has started!
authored
272 #endif
Something went wrong with that request. Please try again.