-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbxphpfpdf.php
243 lines (203 loc) · 6.19 KB
/
cbxphpfpdf.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
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://codeboxr.com
* @since 1.0.0
* @package cbxphpfpdf
*
* @wordpress-plugin
* Plugin Name: CBX PHPFPDF Library
* Plugin URI: https://github.com/codeboxrcodehub/cbxphpfpdf
* Description: fpdf library as WordPress plugin based on https://github.com/fawno/FPDF
* Version: 1.0.0
* Author: Codeboxr
* Author URI: https://github.com/PHPOffice/PhpDomPDF
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: cbxphpfpdf
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
use Cbx\Phpfpdf\Hooks;
defined('CBXPHPFPDF_PLUGIN_NAME') or define('CBXPHPFPDF_PLUGIN_NAME', 'cbxphpfpdf');
defined('CBXPHPFPDF_PLUGIN_VERSION') or define('CBXPHPFPDF_PLUGIN_VERSION', '1.0.0');
defined('CBXPHPFPDF_BASE_NAME') or define('CBXPHPFPDF_BASE_NAME', plugin_basename(__FILE__));
defined('CBXPHPFPDF_ROOT_PATH') or define('CBXPHPFPDF_ROOT_PATH', plugin_dir_path(__FILE__));
defined('CBXPHPFPDF_ROOT_URL') or define('CBXPHPFPDF_ROOT_URL', plugin_dir_url(__FILE__));
register_activation_hook(__FILE__, array('CBXPhpFpdf', 'activation'));
require_once CBXPHPFPDF_ROOT_PATH . "lib/vendor/autoload.php";
/**
* Class CBXPhpFpdf
*/
class CBXPhpFpdf
{
function __construct()
{
//load text domain
load_plugin_textdomain('cbxphpfpdf', false, dirname(plugin_basename(__FILE__)) . '/languages/');
add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
new Hooks();
}
/**
* Activation hook
*/
public static function activation()
{
/*$requirements = array(
'PHP 7.1.0' => version_compare(PHP_VERSION, '7.1.0', '>='),
'PHP extension XML' => extension_loaded('xml'),
'PHP extension xmlwriter' => extension_loaded('xmlwriter'),
'PHP extension mbstring' => extension_loaded('mbstring'),
'PHP extension ZipArchive' => extension_loaded('zip'),
'PHP extension GD (optional)' => extension_loaded('gd'),
'PHP extension dom (optional)' => extension_loaded('dom'),
);*/
if (!CBXPhpFpdf::php_version_check()) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = esc_html__('This plugin requires PHP version 7.1 or newer', 'cbxphpfpdf');
die($error_message);
}
if (!CBXPhpFpdf::php_zip_enabled_check()) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = esc_html__('This plugin requires PHP php_zip extension installed and enabled', 'cbxphpfpdf');
die($error_message);
}
if (!CBXPhpFpdf::php_xml_enabled_check()) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = esc_html__('This plugin requires PHP php_xml extension installed and enabled', 'cbxphpfpdf');
die($error_message);
}
if (!CBXPhpFpdf::php_gd_enabled_check()) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = esc_html__('This plugin requires PHP php_gd2 extension installed and enabled', 'cbxphpfpdf');
die($error_message);
}
if (!CBXPhpFpdf::php_mbstring_enabled_check()) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = esc_html__('This plugin requires PHP php_MBString extension installed and enabled', 'cbxphpfpdf');
die($error_message);
}
if (!CBXPhpFpdf::php_dom_enabled_check()) {
// Deactivate the plugin
deactivate_plugins(__FILE__);
// Throw an error in the wordpress admin console
$error_message = esc_html__('This plugin requires PHP DOM extension installed and enabled', 'cbxphpfpdf');
die($error_message);
}
}//end method activation
/**
* PHP version compatibility check
*
* @return bool
*/
public static function php_version_check()
{
if (version_compare(PHP_VERSION, '7.1.0', '<')) {
return false;
}
return true;
}//end method php_version_check
/**
* php_zip enabled check
*
* @return bool
*/
public static function php_zip_enabled_check()
{
if (extension_loaded('zip')) {
return true;
}
return false;
}//end method php_zip_enabled_check
/**
* php_xml enabled check
*
* @return bool
*/
public static function php_xml_enabled_check()
{
if (extension_loaded('xml')) {
return true;
}
return false;
}//end method php_xml_enabled_check
/**
* php_gd2 enabled check
*
* @return bool
*/
public static function php_gd_enabled_check()
{
if (extension_loaded('gd')) {
return true;
}
return false;
}//end method php_gd_enabled_check
/**
* php_mbstring enabled check
*
* @return bool
*/
public static function php_mbstring_enabled_check()
{
if (extension_loaded('mbstring')) {
return true;
}
return false;
}//end method php_mbstring_enabled_check
/**
* php_dom enabled check
*
* @return bool
*/
public static function php_dom_enabled_check()
{
if (extension_loaded('dom')) {
return true;
}
return false;
}//end method php_dom_enabled_check
/**
* Plugin support and doc page url
*
* @param $links
* @param $file
*
* @return array
*/
public function plugin_row_meta($links, $file)
{
if (strpos($file, 'cbxphpfpdf.php') !== false) {
$new_links = array(
'support' => '<a href="https://github.com/codeboxrcodehub/cbxphpfpdf" target="_blank">' . esc_html__('Support', 'cbxphpfpdf') . '</a>',
'doc' => '<a href="https://github.com/dompdf/dompdf" target="_blank">' . esc_html__('PHP Dompdf Doc', 'cbxphpfpdf') . '</a>'
);
$links = array_merge($links, $new_links);
}
return $links;
}
}//end method CBXPhpFpdf
function cbxphpfpdf_load_plugin()
{
new CBXPhpFpdf();
}
add_action('plugins_loaded', 'cbxphpfpdf_load_plugin', 5);