-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphpwkhtmltopdf.c
More file actions
121 lines (101 loc) · 2.36 KB
/
phpwkhtmltopdf.c
File metadata and controls
121 lines (101 loc) · 2.36 KB
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
112
113
114
115
116
117
118
119
120
121
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <stdio.h>
#include "php.h"
#include "phpwkhtmltopdf.h"
ZEND_DECLARE_MODULE_GLOBALS(phpwkhtmltopdf)
static zend_function_entry phpwkhtmltopdf_functions[] =
{
PHP_FE(wkhtmltopdf_convert, NULL)
{
NULL, NULL, NULL
}
};
static int run_cmd(char *cmd, char *result)
{
FILE *pp;
int iRet = 0;
if((pp = popen(cmd, "r")) == NULL)
{
strcpy(result, "popen error!");
return -1;
}
fgets(result, 999, pp);
iRet = pclose(pp);
return iRet;
}
PHP_MINIT_FUNCTION(phpwkhtmltopdf)
{
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(phpwkhtmltopdf)
{
return SUCCESS;
}
PHP_RINIT_FUNCTION(phpwkhtmltopdf)
{
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(phpwkhtmltopdf)
{
return SUCCESS;
}
PHP_MINFO_FUNCTION(phpwkhtmltopdf)
{
char result[1000] = {0};
int res = run_cmd("wkhtmltopdf --version", &result);
php_info_print_table_start();
php_info_print_table_row(2, "phpwkhtmltopdf", "enabled");
php_info_print_table_row(2, "phpwkhtmltopdf version", result);
php_info_print_table_end();
}
zend_module_entry phpwkhtmltopdf_module_entry =
{
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_PHPWKHTMLTOPDF_EXTNAME,
phpwkhtmltopdf_functions,
PHP_MINIT(phpwkhtmltopdf),
PHP_MSHUTDOWN(phpwkhtmltopdf),
PHP_RINIT(phpwkhtmltopdf),
PHP_RSHUTDOWN(phpwkhtmltopdf),
PHP_MINFO(phpwkhtmltopdf),
#if ZEND_MODULE_API_NO >= 20010901
PHP_PHPWKHTMLTOPDF_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_PHPWKHTMLTOPDF
ZEND_GET_MODULE(phpwkhtmltopdf)
#endif
/**
* bool wkhtmltopdf_convert(source, des)
*/
PHP_FUNCTION(wkhtmltopdf_convert)
{
// used for iterating over the object params
zval *data;
HashTable *params_hash;
HashPosition pointer;
int params_count;
// temporarily holds return value
int ret;
// source file and des file
char *source;
size_t source_len;
char *des;
size_t des_len;
char command[1000] = {0};
// parse out parameters passed
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&source, &source_len, &des, &des_len) == FAILURE)
{
RETURN_NULL();
}
sprintf(command, "wkhtmltopdf %s %s", source, des);
ret = system(command);
RETVAL_BOOL(ret == 0);
}