forked from GravityPDF/gravity-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.php
419 lines (347 loc) · 11.5 KB
/
pdf.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<?php
/*
Plugin Name: Gravity PDF
Version: 5.0.0-RC2
Description: Automatically generate highly-customisable PDF documents using Gravity Forms.
Author: Gravity PDF
Author URI: https://gravitypdf.com
Text Domain: gravity-forms-pdf-extended
Domain Path: /src/assets/languages
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/*
This file is part of Gravity PDF
Gravity PDF – Copyright (C) 2018 Blue Liquid Designs
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Set base constants we'll use throughout the plugin
*/
define( 'PDF_EXTENDED_VERSION', '5.0.0-RC2' ); /* the current plugin version */
define( 'PDF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); /* plugin directory path */
define( 'PDF_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); /* plugin directory url */
define( 'PDF_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); /* the plugin basename */
/*
* Add our activation hook and deactivation hooks
*/
require_once PDF_PLUGIN_DIR . 'src/controller/Controller_Activation.php';
register_deactivation_hook( __FILE__, array( 'Controller_Activation', 'deactivation' ) );
/**
*
* Our initialisation class
* Check all the dependancy requirements are met, otherwise fallback and show appropriate user error
*
* @since 4.0
*/
class GFPDF_Major_Compatibility_Checks {
/**
* The plugin's basename
*
* @var string
*
* @since 4.0
*/
private $basename;
/**
* The path to the plugin
*
* @var string
*
* @since 4.0
*/
private $path;
/**
* Holds any blocker error messages stopping plugin running
*
* @var array
*
* @since 4.0
*/
private $notices = array();
/**
* The plugin's required Gravity Forms version
*
* @var string
*
* @since 4.0
*/
public $required_gf_version = '2.3.1';
/**
* The plugin's required WordPress version
*
* @var string
*
* @since 4.0
*/
public $required_wp_version = '4.8';
/**
* The plugin's required PHP version
*
* Gravity PDF 4.0 is such a major release that we can afford to also bump up the version requirements.
* We really wanted to bump this up to an actively supported version of PHP (http://php.net/supported-versions.php)
* but with WordPress supporting PHP5.2+ (and making no moves to increase this) we had to strike a balance.
*
* The initial release will require PHP 5.4 which will strike a better balance.
*
* @var string
*
* @since 4.0
*/
public $required_php_version = '5.6';
/**
* Set our required variables for a fallback and attempt to initialise
*
* @param string $basename Plugin basename
* @param string $path The plugin path
*
* @since 4.0
*/
public function __construct( $basename = '', $path = '' ) {
/* Set our class variables */
$this->basename = $basename;
$this->path = $path;
}
/**
* Load the plugin
*
* @return void
*
* @since 4.0
*/
public function init() {
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
}
/**
* Check if dependancies are met and load plugin, otherwise display errors
*
* @return void
*
* @since 4.0
*/
public function plugins_loaded() {
/* Check minimum requirements are met */
$this->is_compatible_wordpress_version();
$this->check_gravity_forms();
$this->check_php();
$this->check_mb_string();
$this->check_mb_string_regex();
$this->check_gd();
$this->check_dom();
$this->check_ram( ini_get( 'memory_limit' ) );
/* Check if any errors were thrown, enqueue them and exit early */
if ( sizeof( $this->notices ) > 0 ) {
add_action( 'admin_notices', array( $this, 'display_notices' ) );
return null;
}
require_once $this->path . 'src/bootstrap.php';
}
/**
* Check if WordPress version is compatible
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function is_compatible_wordpress_version() {
global $wp_version;
/* WordPress version not compatible */
if ( ! version_compare( $wp_version, $this->required_wp_version, '>=' ) ) {
$this->notices[] = sprintf( esc_html__( 'WordPress Version %s is required. %sGet more info%s.', 'gravity-forms-pdf-extended' ), $this->required_wp_version, '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#wordpress-version">', '</a>' );
return false;
}
return true;
}
/**
* Check if Gravity Forms version is compatible
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_gravity_forms() {
/* Gravity Forms version not compatible */
if ( ! class_exists( 'GFCommon' ) || ! version_compare( GFCommon::$version, $this->required_gf_version, '>=' ) ) {
$this->notices[] = sprintf( esc_html__( '%sGravity Forms%s Version %s is required. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://rocketgenius.pxf.io/c/1211356/445235/7938">', '</a>', $this->required_gf_version, '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#gravityforms-version">', '</a>' );
return false;
}
return true;
}
/**
* Check if PHP version is compatible
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_php() {
/* Check PHP version is compatible */
if ( ! version_compare( phpversion(), $this->required_php_version, '>=' ) ) {
$this->notices[] = sprintf( esc_html__( 'You are running an %soutdated version of PHP%s. Contact your web hosting provider to update. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="http://www.wpupdatephp.com/update/">', '</a>', '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#php-version">', '</a>' );
return false;
}
return true;
}
/**
* Check if PHP MB String enabled
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_mb_string() {
/* Check MB String is installed */
if ( ! extension_loaded( 'mbstring' ) ) {
$this->notices[] = sprintf( esc_html__( 'The PHP Extension MB String could not be detected. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#php-mbstring">', '</a>' );
return false;
}
return true;
}
/**
* Check if MB String Regex enabled
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_mb_string_regex() {
/* Check MB String is compiled with regex capabilities */
if ( extension_loaded( 'mbstring' ) && ! function_exists( 'mb_regex_encoding' ) ) {
$this->notices[] = sprintf( esc_html__( 'The PHP Extension MB String does not have MB Regex enabled. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#php-mbstring-regex">', '</a>' );
return false;
}
return true;
}
/**
* Check if PHP GD Library installed
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_gd() {
/* Check GD Image Library is installed */
if ( ! extension_loaded( 'gd' ) ) {
$this->notices[] = sprintf( esc_html__( 'The PHP Extension GD Image Library could not be detected. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#php-gd">', '</a>' );
return false;
}
return true;
}
/**
* Check if PHP DOM / libxml installed
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_dom() {
/* Check DOM Class is installed */
if ( ! extension_loaded( 'dom' ) || ! class_exists( 'DOMDocument' ) ) {
$this->notices[] = sprintf( esc_html__( 'The PHP DOM Extension was not found. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#php-dom">', '</a>' );
return false;
}
/* Check libxml is loaded */
if ( ! extension_loaded( 'libxml' ) ) {
$this->notices[] = sprintf( esc_html__( 'The PHP Extension libxml could not be detected. Contact your web hosting provider to fix. %sGet more info%s.', 'gravity-forms-pdf-extended' ), '<a href="https://gravitypdf.com/documentation/v5/user-activation-errors/#php-xml">', '</a>' );
return false;
}
return true;
}
/**
* Check if minimum RAM requirements met
*
* @param string $ram The PHP RAM setting
*
* @return boolean Whether compatible or not
*
* @since 4.0
*/
public function check_ram( $ram ) {
/* Check Minimum RAM requirements */
$ram = $this->get_ram( $ram );
if ( $ram < 64 && $ram !== -1 ) {
$this->notices[] = sprintf( esc_html__( "You need %s128MB%s of WP Memory (RAM) but we only found %s available. %sTry these methods to increase your memory limit%s, otherwise contact your web hosting provider to fix.", 'gravity-forms-pdf-extended' ), '<strong>', '</strong>', $ram . 'MB', '<a href="https://gravitypdf.com/documentation/v5/user-increasing-memory-limit/">', '</a>' );
return false;
}
return true;
}
/**
* Get the available system memory
*
* @param string $ram The PHP RAM setting
*
* @return integer The calculated RAM
*
* @since 4.0
*/
public function get_ram( $ram ) {
/* Get memory in standardised bytes format */
$memory_limit = $this->convert_ini_memory( $ram );
/* Convert to megabytes, or set to -1 if unlimited */
return ( $memory_limit === '-1' ) ? -1 : floor( $memory_limit / 1024 / 1024 );
}
/**
* Convert .ini file memory to bytes
*
* @param string $memory The .ini memory limit
*
* @return integer The calculated memory limit in bytes
*/
public function convert_ini_memory( $memory ) {
$convert = array( 'mb' => 'm', 'kb' => 'k', 'gb' => 'g' );
/* Standardise format */
foreach ( $convert as $k => $v ) {
$memory = str_ireplace( $k, $v, $memory );
}
/* Check if memory allocation is in mb, kb or gb */
switch ( strtolower( substr( $memory, -1 ) ) ) {
case 'm':
return (int) $memory * 1048576;
case 'k':
return (int) $memory * 1024;
case 'g':
return (int) $memory * 1073741824;
}
return $memory;
}
/**
* Helper function to easily display error messages
*
* @return void
*
* @since 4.0
*/
public function display_notices() {
?>
<div class="error">
<p><strong><?php esc_html_e( 'Gravity PDF Installation Problem', 'gravity-forms-pdf-extended' ); ?></strong></p>
<p><?php esc_html_e( 'The minimum requirements for Gravity PDF have not been met. Please fix the issue(s) below to continue:', 'gravity-forms-pdf-extended' ); ?></p>
<ul style="padding-bottom: 0.5em">
<?php foreach ( $this->notices as $notice ) : ?>
<li style="padding-left: 20px;list-style: inside"><?php echo $notice; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php
}
}
/*
* Initialise the software
*/
$gravitypdf = new GFPDF_Major_Compatibility_Checks(
PDF_PLUGIN_BASENAME,
PDF_PLUGIN_DIR
);
$gravitypdf->init();