forked from andrewklimek/formidable-pro-pdf-extended
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdf-common.php
264 lines (217 loc) · 6.74 KB
/
pdf-common.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
class FPPDF_Common
{
public static function setup_ids()
{
global $form_id, $lead_id, $lead_ids;
$form_id = $form_id ? $form_id : absint( filter_input(INPUT_GET,"fid") );
$lead_ids = $lead_id ? array($lead_id) : explode(',', filter_input(INPUT_GET,"lid"));
/**
* If form ID and lead ID hasn't been set stop the PDF from attempting to generate
*/
if(empty($form_id) || empty($lead_ids))
{
trigger_error(__('Form Id and Lead Id are required parameters.', "formidablepropdfextended"));
return;
}
}
/*
* Remove any form fields with pdf_hidden in the class name
*/
public static function get_form_fields($form_id)
{
$fields = FrmField::getAll(array('fi.form_id' => $form_id), 'field_order');
foreach($fields as $k => $f){
if(strpos($f->field_options['classes'], 'pdf_hidden') !== false)
{
unset($fields[$k]);
}
}
return $fields;
}
/*
* Check if the system is fully installed and return the correct values
*/
public static function is_fully_installed() {
global $frmpro_is_installed;
if ( ! $frmpro_is_installed ) {
if ( ! is_callable( 'FrmAppHelper::pro_is_installed' ) || ! FrmAppHelper::pro_is_installed() ){
return false;
}
}
if( (get_option('fp_pdf_extended_installed') != 'installed') || (!is_dir(FP_PDF_TEMPLATE_LOCATION)) )
{
return false;
}
if(get_option('fp_pdf_extended_version') != FP_PDF_EXTENDED_VERSION)
{
return false;
}
if(get_option('fp_pdf_extended_deploy') == 'no' && !filter_input(INPUT_POST,'upgrade') && FP_PDF_DEPLOY === true)
{
return false;
}
if(file_exists(FP_PDF_PLUGIN_DIR .'mPDF.zip'))
{
return false;
}
return true;
}
public static function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
public static function get_html_template($filename)
{
global $form_id, $lead_id, $lead_ids;
ob_start();
require($filename);
$page = ob_get_contents();
ob_end_clean();
return $page;
}
/**
* Get the name of the PDF based on the Form and the submission
*/
public static function get_pdf_filename($form_id, $lead_id)
{
return "form-$form_id-entry-$lead_id.pdf";
}
/*
* We need to validate the PDF name
* Check the size limit, if the file name's syntax is correct
* and strip any characters that aren't classed as valid file name characters.
*/
public static function validate_pdf_name($name, $form_id = false, $lead_id = false)
{
$pdf_name = $name;
if($form_id > 0)
{
$pdf_name = self::do_mergetags($pdf_name, $form_id, $lead_id);
}
/*
* Limit the size of the filename to 150 characters
*/
if(strlen($pdf_name) > 150)
{
$pdf_name = substr($pdf_name, 0, 150);
}
/*
* Remove extension from the end of the filename so we can replace all '.'
* Will add back before we are finished
*/
if(substr($pdf_name, -4) == '.pdf')
{
$pdf_name = substr($pdf_name, 0, -4);
}
/*
* Remove any invalid (mostly Windows) characters from filename
*/
$pdf_name = str_replace( ['/', '\\', '"', '*', '?', '|', ':', '<', '>', '.'], '-', $pdf_name );
$pdf_name = $pdf_name . '.pdf';
return $pdf_name;
}
public static function do_mergetags($string, $form_id, $entry_id)
{
/* strip {all_fields} merge tag from $string */
$string = str_replace('[default-message]', '', $string);
$entry = FrmEntry::getOne($entry_id, true);
$shortcodes = FrmProDisplaysHelper::get_shortcodes($string, $form_id);
return FrmProContent::replace_shortcodes($string, $entry, $shortcodes);
}
public static function view_data($form_data)
{
if(isset($_GET['data']) && $_GET['data'] === '1')
{
print '<pre>';
print_r($form_data);
print '</pre>';
exit;
}
}
public static function is_formidable_supported( $version ) {
if ( ! class_exists('FrmProDisplay') ) {
return false;
}
global $frm_version;
if ( $frm_version ) {
/**
* Get the plugin version when < 2.0
*/
$current_frm_version = $frm_version;
} else if ( is_callable( 'FrmAppHelper::plugin_version' ) ) {
/**
* Get the plugin version when > 2.0
*/
$current_frm_version = FrmAppHelper::plugin_version();
}
if ( version_compare( $current_frm_version, $version, '>=' ) === true ) {
global $frmpro_is_installed;
if ( $frmpro_is_installed ) {
return true;
}
/**
* Check if pro is installed in 2.0+
*/
return ( is_callable( 'FrmAppHelper::pro_is_installed' ) && FrmAppHelper::pro_is_installed() );
}
return false;
}
public static function is_wordpress_supported($version){
global $wp_version;
if(version_compare($wp_version, $version, ">=") === true)
{
return true;
}
return false;
}
public static function display_compatibility_error()
{
$message = "Formidable Pro " . FP_PDF_EXTENDED_SUPPORTED_VERSION . " is required to use this plugin. Activate/Upgrade now or purchase it today!";
FPPDF_Common::display_plugin_message($message, true);
}
public static function display_wp_compatibility_error()
{
$message = "Wordpress " . FP_PDF_EXTENDED_WP_SUPPORTED_VERSION . " or higher is required to use this plugin.";
FPPDF_Common::display_plugin_message($message, true);
}
public static function display_plugin_message($message, $is_error = false){
$notice_type_class = $is_error ? ' notice-error' : ' notice-info';
echo '</tr><tr class="plugin-update-tr"><td colspan=3 class="plugin-update"><div class="update-message notice inline notice-alt' . $notice_type_class . '">' . $message . '</div></td>';
}
/*
* New to 3.0.2 we will use WP_Filesystem API to manipulate files instead of using in-built PHP functions
* $post Array the post data to include in the request_filesystem_credntials API
*/
public static function initialise_WP_filesystem_API($post, $nonce)
{
$url = FP_PDF_SETTINGS_URL;
if (false === ($creds = request_filesystem_credentials($url, '', false, false, $post) ) ) {
/*
* If we get here, then we don't have correct permissions and we need to get the FTP details.
* request_filesystem_credentials will handle all that
*/
return false; // stop the normal page form from displaying
}
/*
* Check if the credentials are no good and display an error
*/
if ( ! WP_Filesystem($creds) ) {
request_filesystem_credentials($url, '', true, false, null);
return false;
}
return true;
}
}