1+ <?php
2+
3+ /**
4+ * The plugin bootstrap file
5+ *
6+ * This file is read by WordPress to generate the plugin information in the plugin
7+ * admin area. This file also includes all of the dependencies used by the plugin,
8+ * registers the activation and deactivation functions, and defines a function
9+ * that starts the plugin.
10+ *
11+ * @link http://codeboxr.com
12+ * @since 1.0.0
13+ * @package cbxphpfpdf
14+ *
15+ * @wordpress-plugin
16+ * Plugin Name: CBX PHPFPDF Library
17+ * Plugin URI: https://github.com/codeboxrcodehub/cbxphpfpdf
18+ * Description: fpdf library as WordPress plugin based on https://github.com/fawno/FPDF
19+ * Version: 1.0.0
20+ * Author: Codeboxr
21+ * Author URI: https://github.com/PHPOffice/PhpDomPDF
22+ * License: GPL-2.0+
23+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
24+ * Text Domain: cbxphpfpdf
25+ * Domain Path: /languages
26+ */
27+
28+ // If this file is called directly, abort.
29+ if (!defined ('WPINC ' )) {
30+ die;
31+ }
32+ use Cbx \Phpfpdf \Hooks ;
33+
34+ defined ('CBXPHPFPDF_PLUGIN_NAME ' ) or define ('CBXPHPFPDF_PLUGIN_NAME ' , 'cbxphpfpdf ' );
35+ defined ('CBXPHPFPDF_PLUGIN_VERSION ' ) or define ('CBXPHPFPDF_PLUGIN_VERSION ' , '1.0.0 ' );
36+ defined ('CBXPHPFPDF_BASE_NAME ' ) or define ('CBXPHPFPDF_BASE_NAME ' , plugin_basename (__FILE__ ));
37+ defined ('CBXPHPFPDF_ROOT_PATH ' ) or define ('CBXPHPFPDF_ROOT_PATH ' , plugin_dir_path (__FILE__ ));
38+ defined ('CBXPHPFPDF_ROOT_URL ' ) or define ('CBXPHPFPDF_ROOT_URL ' , plugin_dir_url (__FILE__ ));
39+
40+ register_activation_hook (__FILE__ , array ('CBXPhpFpdf ' , 'activation ' ));
41+ require_once CBXPHPFPDF_ROOT_PATH . "lib/vendor/autoload.php " ;
42+
43+ /**
44+ * Class CBXPhpFpdf
45+ */
46+ class CBXPhpFpdf
47+ {
48+ function __construct ()
49+ {
50+ //load text domain
51+ load_plugin_textdomain ('cbxphpfpdf ' , false , dirname (plugin_basename (__FILE__ )) . '/languages/ ' );
52+
53+ add_filter ('plugin_row_meta ' , array ($ this , 'plugin_row_meta ' ), 10 , 2 );
54+ new Hooks ();
55+ }
56+
57+ /**
58+ * Activation hook
59+ */
60+ public static function activation ()
61+ {
62+ /*$requirements = array(
63+ 'PHP 7.1.0' => version_compare(PHP_VERSION, '7.1.0', '>='),
64+ 'PHP extension XML' => extension_loaded('xml'),
65+ 'PHP extension xmlwriter' => extension_loaded('xmlwriter'),
66+ 'PHP extension mbstring' => extension_loaded('mbstring'),
67+ 'PHP extension ZipArchive' => extension_loaded('zip'),
68+ 'PHP extension GD (optional)' => extension_loaded('gd'),
69+ 'PHP extension dom (optional)' => extension_loaded('dom'),
70+ );*/
71+
72+ if (!CBXPhpFpdf::php_version_check ()) {
73+
74+ // Deactivate the plugin
75+ deactivate_plugins (__FILE__ );
76+
77+ // Throw an error in the wordpress admin console
78+ $ error_message = esc_html__ ('This plugin requires PHP version 7.1 or newer ' , 'cbxphpfpdf ' );
79+ die ($ error_message );
80+ }
81+
82+ if (!CBXPhpFpdf::php_zip_enabled_check ()) {
83+
84+ // Deactivate the plugin
85+ deactivate_plugins (__FILE__ );
86+
87+ // Throw an error in the wordpress admin console
88+ $ error_message = esc_html__ ('This plugin requires PHP php_zip extension installed and enabled ' , 'cbxphpfpdf ' );
89+ die ($ error_message );
90+ }
91+
92+ if (!CBXPhpFpdf::php_xml_enabled_check ()) {
93+
94+ // Deactivate the plugin
95+ deactivate_plugins (__FILE__ );
96+
97+ // Throw an error in the wordpress admin console
98+ $ error_message = esc_html__ ('This plugin requires PHP php_xml extension installed and enabled ' , 'cbxphpfpdf ' );
99+ die ($ error_message );
100+ }
101+
102+ if (!CBXPhpFpdf::php_gd_enabled_check ()) {
103+
104+ // Deactivate the plugin
105+ deactivate_plugins (__FILE__ );
106+
107+ // Throw an error in the wordpress admin console
108+ $ error_message = esc_html__ ('This plugin requires PHP php_gd2 extension installed and enabled ' , 'cbxphpfpdf ' );
109+ die ($ error_message );
110+ }
111+
112+ if (!CBXPhpFpdf::php_mbstring_enabled_check ()) {
113+
114+ // Deactivate the plugin
115+ deactivate_plugins (__FILE__ );
116+
117+ // Throw an error in the wordpress admin console
118+ $ error_message = esc_html__ ('This plugin requires PHP php_MBString extension installed and enabled ' , 'cbxphpfpdf ' );
119+ die ($ error_message );
120+ }
121+
122+ if (!CBXPhpFpdf::php_dom_enabled_check ()) {
123+
124+ // Deactivate the plugin
125+ deactivate_plugins (__FILE__ );
126+
127+ // Throw an error in the wordpress admin console
128+ $ error_message = esc_html__ ('This plugin requires PHP DOM extension installed and enabled ' , 'cbxphpfpdf ' );
129+ die ($ error_message );
130+ }
131+
132+ }//end method activation
133+
134+ /**
135+ * PHP version compatibility check
136+ *
137+ * @return bool
138+ */
139+ public static function php_version_check ()
140+ {
141+ if (version_compare (PHP_VERSION , '7.1.0 ' , '< ' )) {
142+ return false ;
143+ }
144+
145+ return true ;
146+ }//end method php_version_check
147+
148+ /**
149+ * php_zip enabled check
150+ *
151+ * @return bool
152+ */
153+ public static function php_zip_enabled_check ()
154+ {
155+ if (extension_loaded ('zip ' )) {
156+ return true ;
157+ }
158+ return false ;
159+ }//end method php_zip_enabled_check
160+
161+ /**
162+ * php_xml enabled check
163+ *
164+ * @return bool
165+ */
166+ public static function php_xml_enabled_check ()
167+ {
168+ if (extension_loaded ('xml ' )) {
169+ return true ;
170+ }
171+ return false ;
172+ }//end method php_xml_enabled_check
173+
174+ /**
175+ * php_gd2 enabled check
176+ *
177+ * @return bool
178+ */
179+ public static function php_gd_enabled_check ()
180+ {
181+ if (extension_loaded ('gd ' )) {
182+ return true ;
183+ }
184+ return false ;
185+ }//end method php_gd_enabled_check
186+
187+ /**
188+ * php_mbstring enabled check
189+ *
190+ * @return bool
191+ */
192+ public static function php_mbstring_enabled_check ()
193+ {
194+ if (extension_loaded ('mbstring ' )) {
195+ return true ;
196+ }
197+ return false ;
198+ }//end method php_mbstring_enabled_check
199+
200+ /**
201+ * php_dom enabled check
202+ *
203+ * @return bool
204+ */
205+ public static function php_dom_enabled_check ()
206+ {
207+ if (extension_loaded ('dom ' )) {
208+ return true ;
209+ }
210+ return false ;
211+ }//end method php_dom_enabled_check
212+
213+ /**
214+ * Plugin support and doc page url
215+ *
216+ * @param $links
217+ * @param $file
218+ *
219+ * @return array
220+ */
221+ public function plugin_row_meta ($ links , $ file )
222+ {
223+ if (strpos ($ file , 'cbxphpfpdf.php ' ) !== false ) {
224+ $ new_links = array (
225+ 'support ' => '<a href="https://github.com/codeboxrcodehub/cbxphpfpdf" target="_blank"> ' . esc_html__ ('Support ' , 'cbxphpfpdf ' ) . '</a> ' ,
226+ 'doc ' => '<a href="https://github.com/dompdf/dompdf" target="_blank"> ' . esc_html__ ('PHP Dompdf Doc ' , 'cbxphpfpdf ' ) . '</a> '
227+ );
228+
229+ $ links = array_merge ($ links , $ new_links );
230+ }
231+
232+ return $ links ;
233+ }
234+
235+ }//end method CBXPhpFpdf
236+
237+
238+ function cbxphpfpdf_load_plugin ()
239+ {
240+ new CBXPhpFpdf ();
241+ }
242+
243+ add_action ('plugins_loaded ' , 'cbxphpfpdf_load_plugin ' , 5 );
0 commit comments