PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 2.4.0
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v2.4.0
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / pdf-print.php

pdf-print.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 2.4.0, at pdf-print.php

2,059 lines 74.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: PDF & Print by BestWebSoft
4 Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/pdf-print/
5 Description: Generate PDF files and print WordPress posts/pages. Customize document header/footer styles and appearance.
6 Author: BestWebSoft
7 Text Domain: pdf-print
8 Domain Path: /languages
9 Version: 2.4.0
10 Author URI: https://bestwebsoft.com/
11 License: GPLv2 or later
12 */
13
14 /**
15 © Copyright 2021 BestWebSoft ( https://support.bestwebsoft.com )
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License, version 2, as
19 published by the Free Software Foundation.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 if ( ! defined( 'ABSPATH' ) ) {
32 exit;
33 }
34
35 require_once dirname( __FILE__ ) . '/includes/deprecated.php';
36
37 if ( ! function_exists( 'pdfprnt_add_admin_menu' ) ) {
38 /**
39 * Add our own menu
40 */
41 function pdfprnt_add_admin_menu() {
42 global $submenu, $pdfprnt_plugin_info, $wp_version, $pdfprnt_options;
43 if ( ! is_plugin_active( 'pdf-print-pro/pdf-print-pro.php' )/*pls */ && ! is_plugin_active( 'pdf-print-plus/pdf-print-plus.php' )/* pls*/ ) {
44 $settings = add_menu_page( esc_html__( 'PDF & Print Settings', 'pdf-print' ), 'PDF & Print', 'manage_options', 'pdf-print.php', 'pdfprnt_settings_page' );
45 add_submenu_page( 'pdf-print.php', esc_html__( 'PDF & Print Settings', 'pdf-print' ), esc_html__( 'Settings', 'pdf-print' ), 'manage_options', 'pdf-print.php', 'pdfprnt_settings_page' );
46 add_submenu_page( 'pdf-print.php', esc_html__( 'Headers & Footers', 'pdf-print' ), esc_html__( 'Headers & Footers', 'pdf-print' ), 'manage_options', 'pdf-print-templates.php', 'pdfprnt_templates' );
47 add_submenu_page( 'pdf-print.php', 'BWS Panel', 'BWS Panel', 'manage_options', 'pdfprnt-bws-panel', 'bws_add_menu_render' );
48 if ( isset( $submenu['pdf-print.php'] ) ) {
49 $submenu['pdf-print.php'][] = array(
50 '<span style="color:#d86463"> ' . esc_html__( 'Upgrade to Pro', 'pdf-print' ) . '</span>',
51 'manage_options',
52 'https://bestwebsoft.com/products/wordpress/plugins/pdf-print/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=' . $pdfprnt_plugin_info['Version'] . '&wp_v=' . $wp_version,
53 );
54 }
55
56 add_action( "load-{$settings}", 'pdfprnt_add_tabs' );
57 }
58 }
59 }
60
61 if ( ! function_exists( 'pdfprnt_add_tabs' ) ) {
62 /**
63 * Add help tab on settings page
64 *
65 * @return void
66 */
67 function pdfprnt_add_tabs() {
68 $args = array(
69 'id' => 'pdfprnt',
70 'section' => '200538669',
71 );
72 bws_help_tab( get_current_screen(), $args );
73 }
74 }
75
76 if ( ! function_exists( 'pdfprnt_plugins_loaded' ) ) {
77 /**
78 * Localization
79 */
80 function pdfprnt_plugins_loaded() {
81 /* Internationalization */
82 load_plugin_textdomain( 'pdf-print', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
83 }
84 }
85
86 if ( ! function_exists( 'pdfprnt_init' ) ) {
87 /**
88 * Init plugin
89 */
90 function pdfprnt_init() {
91 global $pdfprnt_plugin_info, $pdfprnt_is_old_php;
92
93 $plugin_basename = plugin_basename( __FILE__ );
94
95 require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php';
96 bws_include_init( $plugin_basename );
97
98 if ( empty( $pdfprnt_plugin_info ) ) {
99 if ( ! function_exists( 'get_plugin_data' ) ) {
100 require_once ABSPATH . 'wp-admin/includes/plugin.php';
101 }
102 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
103 }
104
105 /* check WordPress version */
106 bws_wp_min_version_check( $plugin_basename, $pdfprnt_plugin_info, '4.5' );
107
108 /* check PHP version */
109 $pdfprnt_is_old_php = version_compare( PHP_VERSION, '5.4.0', '<' );
110
111 /* Get/Register and check settings for plugin */
112 if ( ! is_admin() || ( isset( $_GET['page'] ) && 'pdf-print.php' === $_GET['page'] ) ) {
113 pdfprnt_settings();
114 }
115 }
116 }
117
118 if ( ! function_exists( 'pdfprnt_admin_init' ) ) {
119 /**
120 * Admin init
121 */
122 function pdfprnt_admin_init() {
123 global $bws_plugin_info, $pdfprnt_plugin_info, $bws_shortcode_list, $pagenow, $pdfprnt_options;
124
125 if ( empty( $bws_plugin_info ) ) {
126 $bws_plugin_info = array(
127 'id' => '101',
128 'version' => $pdfprnt_plugin_info['Version'],
129 );
130 }
131 /* add PDF&Print to global $bws_shortcode_list */
132 $bws_shortcode_list['pdfprnt'] = array(
133 'name' => 'PDF&Print',
134 'js_function' => 'pdfprnt_shortcode_init',
135 );
136 if ( 'plugins.php' === $pagenow ) {
137 /* Install the option defaults */
138 if ( function_exists( 'bws_plugin_banner_go_pro' ) ) {
139 pdfprnt_settings();
140 bws_plugin_banner_go_pro( $pdfprnt_options, $pdfprnt_plugin_info, 'pdfprnt', 'pdf-print', 'e2f2549f4d70bc4cb9b48071169d264e', '101', 'pdf-print' );
141 }
142 }
143 }
144 }
145
146
147 if ( ! function_exists( 'pdfprnt_plugin_activate' ) ) {
148 /**
149 * Function for activation
150 */
151 function pdfprnt_plugin_activate() {
152 if ( is_multisite() ) {
153 switch_to_blog( 1 );
154 register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' );
155 restore_current_blog();
156 } else {
157 register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' );
158 }
159 }
160 }
161
162 if ( ! function_exists( 'pdfprnt_settings' ) ) {
163 /**
164 * Register settings for plugin
165 */
166 function pdfprnt_settings() {
167 global $pdfprnt_options, $pdfprnt_plugin_info;
168 $options_default = pdfprnt_get_options_default();
169 if ( ! get_option( 'pdfprnt_options' ) ) {
170 add_option( 'pdfprnt_options', $options_default );
171 }
172
173 $pdfprnt_options = get_option( 'pdfprnt_options' );
174 if ( ! isset( $pdfprnt_options['plugin_option_version'] ) || $pdfprnt_options['plugin_option_version'] !== $pdfprnt_plugin_info['Version'] ) {
175 if ( isset( $pdfprnt_options['button_post_types'] ) ) {
176 unset( $options_default['button_post_types'] );
177 }
178 if ( function_exists( 'array_replace_recursive' ) ) {
179 $pdfprnt_options = array_replace_recursive( $options_default, $pdfprnt_options );
180 } else {
181 foreach ( $options_default as $key => $value ) {
182 if (
183 ! isset( $pdfprnt_options[ $key ] ) ||
184 ( isset( $pdfprnt_options[ $key ] ) && is_array( $options_default[ $key ] ) && ! is_array( $pdfprnt_options[ $key ] ) )
185 ) {
186 $pdfprnt_options[ $key ] = $options_default[ $key ];
187 } else {
188 if ( is_array( $options_default[ $key ] ) ) {
189 foreach ( $options_default[ $key ] as $key2 => $value2 ) {
190 if ( ! isset( $pdfprnt_options[ $key ][ $key2 ] ) ) {
191 $pdfprnt_options[ $key ][ $key2 ] = $options_default[ $key ][ $key2 ];
192 }
193 }
194 }
195 }
196 }
197 }
198 $is_old_pro = false === strpos( 'pro-', $pdfprnt_options['plugin_option_version'] ) ? false : true;
199 if ( $is_old_pro ) {
200 foreach ( array( 'pdf', 'print' ) as $button ) {
201 if ( 'none' !== $pdfprnt_options['button_image'][ $button ]['type'] ) {
202 $pdfprnt_options['button_image'][ $button ]['type'] = 'default';
203 $pdfprnt_options['button_image'][ $button ]['image_src'] = plugins_url( "images/{$button}.png", __FILE__ );
204 }
205 }
206 }
207
208 $pdfprnt_options['plugin_option_version'] = $pdfprnt_plugin_info['Version'];
209 $pdfprnt_options['hide_premium_options'] = array();
210 update_option( 'pdfprnt_options', $pdfprnt_options );
211 pdfprnt_plugin_activate();
212 }
213 }
214 }
215
216 if ( ! function_exists( 'pdfprnt_get_options_default' ) ) {
217 /**
218 * Get plugin default settings
219 */
220 function pdfprnt_get_options_default() {
221 global $pdfprnt_plugin_info, $wp_roles;
222
223 /* Variable to verify performance number of once function. */
224 $default_post_types = array();
225 /* Default post types of WordPress. */
226 foreach ( get_post_types(
227 array(
228 'public' => 1,
229 'show_ui' => 1,
230 '_builtin' => true,
231 ),
232 'names'
233 ) as $value ) {
234 $default_post_types[] = $value;
235 }
236 $default_post_types[] = 'pdfprnt_search';
237 $default_post_types[] = 'pdfprnt_archives';
238 $default_post_types[] = 'pdfprnt_blog';
239
240 $enabled_roles = array();
241 $roles = array_keys( $wp_roles->roles );
242 foreach ( $roles as $key => $role ) {
243 $enabled_roles[ $role ] = 1;
244 }
245 $enabled_roles['unauthorized'] = 1;
246
247 $options_default = array(
248 'plugin_option_version' => $pdfprnt_plugin_info['Version'],
249 'button_post_types' => array(
250 'pdf' => $default_post_types,
251 'print' => $default_post_types,
252 ),
253 'buttons_position' => 'top-right',
254 'use_default_css' => 0,
255 'use_custom_css' => 0,
256 'custom_css_code' => '',
257 'do_shorcodes' => 1,
258 'disable_links' => 0,
259 'remove_links' => 0,
260 'show_print_window' => 0,
261 'additional_fonts' => 0,
262 'show_title' => 1,
263 'show_featured_image' => 0,
264 'show_author' => 0,
265 'show_date' => 0,
266 'show_category' => 0,
267 'featured_image_size' => 'thumbnail',
268 'button_image' => array(
269 'pdf' => array(
270 'type' => 'default',
271 'image_src' => plugins_url( 'images/pdf.png', __FILE__ ),
272 ),
273 'print' => array(
274 'type' => 'default',
275 'image_src' => plugins_url( 'images/print.png', __FILE__ ),
276 ),
277 ),
278 'button_title' => array(
279 'pdf' => '',
280 'print' => '',
281 ),
282 'pdf_page_size' => 'A4',
283 'image_to_pdf' => 0,
284 'pdf_margins' => array(
285 'left' => 15,
286 'right' => 15,
287 'top' => 16,
288 'bottom' => 16,
289 ),
290 'first_install' => strtotime( 'now' ),
291 'suggest_feature_banner' => 1,
292 'file_action' => 'open',
293 'enabled_roles' => $enabled_roles,
294 'mpdf_library_version' => '8.1.3',
295 );
296
297 $options_default = apply_filters( 'pdfprnt_get_additional_options_default', $options_default );
298
299 return $options_default;
300 }
301 }
302
303 if ( ! function_exists( 'pdfprnt_settings_page' ) ) {
304 /**
305 * Settings page
306 */
307 function pdfprnt_settings_page() {
308 global $pdfprnt_plugin_info;
309 require_once dirname( __FILE__ ) . '/includes/pro_banners.php';
310 if ( ! class_exists( 'Bws_Settings_Tabs' ) ) {
311 require_once dirname( __FILE__ ) . '/bws_menu/class-bws-settings.php';
312 }
313 require_once dirname( __FILE__ ) . '/includes/class-pdfprnt-settings.php';
314 $page = new Pdfprnt_Settings_Tabs( plugin_basename( __FILE__ ) );
315 if ( method_exists( $page, 'add_request_feature' ) ) {
316 $page->add_request_feature();
317 } ?>
318 <div class="wrap">
319 <h1 class="pdfprnt-title"><?php esc_html_e( 'PDF & Print Settings', 'pdf-print' ); ?></h1>
320 <?php
321 if ( function_exists( 'bws_plugin_promo_banner' ) ) {
322 echo bws_plugin_promo_banner( $pdfprnt_plugin_info, 'pdfprnt_options', 'pdf-print', 'https://bestwebsoft.com/products/wordpress/plugins/pdf-print/?utm_source=wordpress&utm_medium=plugin_banner&utm_campaign=upgrade' );
323 }
324 $page->display_content(); ?>
325 </div>
326 <?php
327 }
328 }
329
330
331 if ( ! function_exists( 'pdfprnt_templates' ) ) {
332 /**
333 * Headers & Footers page
334 */
335 function pdfprnt_templates() {
336 global $wp_version, $pdfprnt_plugin_info, $pdfprnt_options, $pdfprnt_links;
337 require_once dirname( __FILE__ ) . '/includes/pro_banners.php';
338
339 pdfprnt_settings();
340 $bws_hide_premium = bws_hide_premium_options_check( $pdfprnt_options );
341
342 $tab_action = ( isset( $_GET['pdfprnt_tab_action'] ) && 'new' === $_GET['pdfprnt_tab_action'] );
343 if ( $tab_action ) {
344 $page_title = esc_html__( 'Add New', 'pdf-print' );
345 $page_name = esc_html__( 'Header & Footer Template', 'pdf-print' );
346 } else {
347 $page_title = '';
348 $page_name = esc_html__( 'Headers & Footers', 'pdf-print' );
349 }
350 $display_title = ( ! empty( $page_title ) ) ? "$page_title $page_name" : "$page_name";
351 if ( ! isset( $_GET['pdfprnt_tab_action'] ) && ! $bws_hide_premium ) {
352 $display_title .= sprintf(
353 ' <a class="add-new-h2 pdfprnt_add_new_button" href="%s">%s</a>',
354 admin_url( 'admin.php?page=pdf-print-templates.php&pdfprnt_tab_action=new' ),
355 esc_html__( 'Add New', 'pdf-print' )
356 );
357 }
358 ?>
359 <div class="wrap">
360 <h1 class="pdfprnt-title"><?php echo wp_kses_post( $display_title ); ?></h1>
361 <br>
362 <?php if ( $bws_hide_premium ) { ?>
363 <p>
364 <?php
365 esc_html_e( 'This tab contains Pro options only.', 'pdf-print' );
366 echo ' ' . sprintf(
367 esc_html__( '%1$sChange the settings%2$s to view the Pro options.', 'pdf-print' ),
368 '<a href="admin.php?page=pdf-print.php&bws_active_tab=misc">',
369 '</a>'
370 );
371 ?>
372 </p>
373 <?php } else { ?>
374 <div class="bws_pro_version_bloc pdfprnt-pro-feature pdfprnt-pro-feature-templates">
375 <div class="bws_pro_version_table_bloc">
376 <div class="bws_table_bg" style="z-index: 1098;"></div>
377 <div class="bws_pro_version">
378 <?php
379 if ( ! $tab_action ) {
380 $date_format = get_option( 'date_format' );
381 pdfprnt_headers_footers_list_block( $date_format );
382 } else {
383 pdfprnt_headers_footers_editor_block();
384 }
385 ?>
386 </div>
387 </div>
388 <div class="bws_pro_version_tooltip" style="z-index: 1099;">
389 <a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/pdf-print/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo esc_attr( $pdfprnt_plugin_info['Version'] ); ?>&wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="PDF & Print Pro Plugin"><?php esc_html_e( 'Upgrade to Pro', 'pdf-print' ); ?></a>
390 <div class="clear"></div>
391 </div>
392 </div>
393 <?php } ?>
394 </div>
395 <?php
396 }
397 }
398
399 if ( ! function_exists( 'pdfprnt_shortcode' ) ) {
400 /**
401 * PDF&Print shortcode
402 * [bws_pdfprint]
403 *
404 * @param array $attr Attribute for shortcode.
405 */
406 function pdfprnt_shortcode( $attr ) {
407 global $pdfprnt_options, $pdfprnt_is_old_php;
408
409 if ( isset( $_REQUEST['print'] ) || $pdfprnt_is_old_php || ! pdfprnt_is_user_role_enabled() ) {
410 return;
411 }
412
413 $buttons = '';
414 if ( is_home() ) {
415 global $post;
416 $permalink = get_permalink( $post );
417 } else {
418 $permalink = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
419 }
420 $shortcode_atts = shortcode_atts( array( 'display' => 'pdf' ), $attr );
421 $shortcode_atts = str_word_count( $shortcode_atts['display'], 1 );
422
423 foreach ( $shortcode_atts as $value ) {
424 if ( 'pdf' === $value ) {
425 $buttons .= pdfprnt_get_button( 'pdf', $permalink );
426 }
427 if ( 'print' === $value ) {
428 $buttons .= pdfprnt_get_button( 'print', $permalink );
429 }
430 }
431 if ( ! empty( $buttons ) ) {
432 $buttons = sprintf(
433 '<div class="pdfprnt-buttons">%s</div>',
434 $buttons
435 );
436 add_action( 'wp_footer', 'pdfprnt_add_script' );
437 }
438
439 return $buttons;
440 }
441 }
442
443 if ( ! function_exists( 'pdfprnt_shortcode_pagebreak' ) ) {
444 /**
445 * [pdfprnt_shortcode_pagebreak]
446 */
447 function pdfprnt_shortcode_pagebreak() {
448 if ( isset( $_GET['print'] ) && 'pdf' === $_GET['print'] ) {
449 return '<div style="page-break-after:always"></div>';
450 }
451 return '';
452 }
453 }
454
455 if ( ! function_exists( 'pdfprnt_shortcode_button_content' ) ) {
456 /**
457 * Add shortcode content
458 *
459 * @param string $content Post content.
460 */
461 function pdfprnt_shortcode_button_content( $content ) {
462 ?>
463 <div id="pdfprnt" style="display:none;">
464 <fieldset>
465 <?php esc_html_e( 'Add PDF & Print Buttons to your page or post', 'pdf-print' ); ?>
466 <br />
467 <label>
468 <input type="checkbox" name="pdfprnt_selected_pdf" value="pdf" checked="checked" />
469 <?php esc_html_e( 'PDF', 'pdf-print' ); ?>
470 </label>
471 <br />
472 <label>
473 <input type="checkbox" name="pdfprnt_selected_print" value="print" />
474 <?php esc_html_e( 'Print', 'pdf-print' ); ?>
475 </label>
476 <input class="bws_default_shortcode" type="hidden" name="default" value="[bws_pdfprint]" />
477 <div class="clear"></div>
478 </fieldset>
479 </div>
480 <?php
481 $script = "function pdfprnt_shortcode_init() {
482 ( function( $ ) {
483 $( '.mce-reset input[name^=\"pdfprnt_selected\"]' ).change( function() {
484 var result = '';
485 $( '.mce-reset input[name^=\"pdfprnt_selected\"]' ).each( function() {
486 if ( $( this ).is( ':checked' ) ) {
487 result += $( this ).val() + ',';
488 }
489 } );
490
491 if ( '' == result ) {
492 $( '.mce-reset #bws_shortcode_display' ).text( '' );
493 } else {
494 result = result.slice( 0, - 1 );
495 $( '.mce-reset #bws_shortcode_display' ).text( '[bws_pdfprint display=\"' + result + '\"]' );
496 }
497 } );
498 } ) ( jQuery );
499 }";
500
501 wp_register_script( 'pdfprnt_bws_shortcode_button', '//', false, null, false );
502 wp_enqueue_script( 'pdfprnt_bws_shortcode_button' );
503 wp_add_inline_script( 'pdfprnt_bws_shortcode_button', sprintf( $script ) );
504 }
505 }
506
507 if ( ! function_exists( 'pdfprnt_get_button' ) ) {
508 /**
509 * Forming button
510 *
511 * @param string $button button name: 'pdf' or 'print'.
512 * @param string $url page url or permalink.
513 * @param string $custom_query_arg custom query arg to add to query.
514 * @return string $link formed link with image and button title.
515 */
516 function pdfprnt_get_button( $button = 'pdf', $url = '', $custom_query_arg = '' ) {
517 global $pdfprnt_options;
518
519 if ( empty( $url ) ) {
520 $url = home_url( '/' );
521 }
522 $button = ( 'print' === $button ) ? 'print' : 'pdf';
523
524 if ( 'default' === $pdfprnt_options['button_image'][ $button ]['type'] && ! empty( $pdfprnt_options['button_image'][ $button ]['image_src'] ) ) {
525 $image = sprintf(
526 '<img src="%s" alt="image_%s" title="%s" />',
527 esc_url( $pdfprnt_options['button_image'][ $button ]['image_src'] ),
528 $button,
529 ( ( 'print' === $button ) ? esc_html__( 'Print Content', 'pdf-print' ) : ( ( 'open' === $pdfprnt_options['file_action'] ) ? esc_html__( 'View PDF', 'pdf-print' ) : esc_html__( 'Download PDF', 'pdf-print' ) ) )
530 );
531 } else {
532 $image = '';
533 }
534
535 $custom_query_arg = ( ! empty( $custom_query_arg ) ) ? $custom_query_arg : $button;
536 $url = esc_url( $url );
537 $url = add_query_arg( 'print', $custom_query_arg, $url );
538 $target = '_blank';
539
540 $title = ( ! empty( $pdfprnt_options['button_title'][ $button ] ) ) ?
541 sprintf(
542 '<span class="pdfprnt-button-title pdfprnt-button-%s-title">%s</span>',
543 $button,
544 $pdfprnt_options['button_title'][ $button ]
545 )
546 :
547 '';
548 if ( $pdfprnt_options['image_to_pdf'] && 'pdf' === $custom_query_arg ) {
549 $url = 'javascript: imageToPdf()';
550 $target = '_self';
551 }
552 $link = sprintf(
553 '<a href="%s" class="pdfprnt-button pdfprnt-button-%s" target="%s">%s%s</a>',
554 $url,
555 $button,
556 $target,
557 $image,
558 $title
559 );
560
561 $link = apply_filters( 'pdfprnt_add_atribute_rel', $link, $url, $button, $target, $image, $title );
562
563 return $link;
564 }
565 }
566
567 if ( ! function_exists( 'pdfprnt_is_user_role_enabled' ) ) {
568 /**
569 * Check is enabled for user role
570 */
571 function pdfprnt_is_user_role_enabled() {
572 global $pdfprnt_options, $current_user;
573 if ( ! is_user_logged_in() || empty( $current_user->roles ) ) {
574 return ! empty( $pdfprnt_options['enabled_roles']['unauthorized'] );
575 } else {
576 $role = $current_user->roles[0];
577 return ! empty( $pdfprnt_options['enabled_roles'][ $role ] );
578 }
579 }
580 }
581
582 if ( ! function_exists( 'pdfprnt_content' ) ) {
583 /**
584 * Positioning buttons in content of standart posts and pages
585 *
586 * @param string $content Post content.
587 * @return string $content
588 */
589 function pdfprnt_content( $content ) {
590 global $pdfprnt_options, $post, $pdfprnt_is_old_php;
591
592 if ( $pdfprnt_is_old_php || is_admin() || is_feed() || is_search() || is_category() || is_tax() || is_tag() || is_author() || ! pdfprnt_is_user_role_enabled() || post_password_required( $post->ID ) ) {
593 return $content;
594 }
595
596 $show_button_pdf = ! empty( $pdfprnt_options['button_post_types']['pdf'] ) && in_array( $post->post_type, $pdfprnt_options['button_post_types']['pdf'], true );
597 $show_button_print = ! empty( $pdfprnt_options['button_post_types']['print'] ) && in_array( $post->post_type, $pdfprnt_options['button_post_types']['print'], true );
598
599 if ( $show_button_pdf || $show_button_print ) {
600
601 $str = '<div class="pdfprnt-buttons pdfprnt-buttons-' . $post->post_type . ' pdfprnt-' . $pdfprnt_options['buttons_position'] . '">';
602 if ( is_home() ) {
603 $permalink = get_permalink( $post );
604 } else {
605 $permalink = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
606 }
607
608 if ( $show_button_pdf ) {
609 $str .= pdfprnt_get_button( 'pdf', $permalink );
610 if ( ! is_archive() && ! is_home() ) {
611 add_action( 'wp_footer', 'pdfprnt_add_script' );
612 }
613 }
614 if ( $show_button_print ) {
615 $str .= pdfprnt_get_button( 'print', $permalink );
616 }
617 $str .= '</div>';
618
619 if ( 'top-left' === $pdfprnt_options['buttons_position'] || 'top-right' === $pdfprnt_options['buttons_position'] ) {
620 $content = $str . $content;
621 } elseif ( 'bottom-left' === $pdfprnt_options['buttons_position'] || 'bottom-right' === $pdfprnt_options['buttons_position'] ) {
622 $content = $content . $str;
623 } else {
624 $content = $str . $content . $str;
625 }
626 }
627 return $content;
628 }
629 }
630
631 if ( ! function_exists( 'pdfprnt_excerpt' ) ) {
632 /**
633 * Remove Print word from excerpt
634 *
635 * @param string $content Post excerpt.
636 * @return string $content
637 */
638 function pdfprnt_excerpt( $content ) {
639 global $pdfprnt_options;
640 $temp = array();
641 $temp[1] = $content;
642 $title = isset( $pdfprnt_options['button_title'] ) ? $pdfprnt_options['button_title'] : array( 'pdf' => '', 'print' => '' );
643 if ( ! empty( $title['pdf'] ) ) {
644 $temp = explode( $title['pdf'], $content );
645 }
646 if ( ! empty( $title['print'] ) ) {
647 $temp = explode( $title['print'], $content );
648 }
649 if ( isset( $temp[1] ) ) {
650 return $temp[1];
651 } else {
652 return $content;
653 }
654 }
655 }
656
657 if ( ! function_exists( 'pdfprnt_show_buttons_search_archive' ) ) {
658 /**
659 * Output buttons for search or archive pages
660 *
661 * @param string $content Post content.
662 */
663 function pdfprnt_show_buttons_search_archive( $content ) {
664 global $wp_query;
665
666 /* make sure that we display pdf/print buttons only with main loop */
667 if ( is_main_query() && $content === $wp_query ) {
668 global $pdfprnt_options, $wp, $posts, $pdfprnt_show_archive_start, $pdfprnt_show_archive_end;
669
670 $is_search = ( is_search() );
671 $is_archive = ( is_archive() || is_category() || is_tax() || is_tag() || is_author() );
672 $is_blog = ( is_home() );
673
674 if ( $is_search ) {
675 $show_button_pdf = ( in_array( 'pdfprnt_search', $pdfprnt_options['button_post_types']['pdf'], true ) );
676 $show_button_print = ( in_array( 'pdfprnt_search', $pdfprnt_options['button_post_types']['print'], true ) );
677 } elseif ( $is_archive ) {
678 $show_button_pdf = ( in_array( 'pdfprnt_archives', $pdfprnt_options['button_post_types']['pdf'], true ) );
679 $show_button_print = ( in_array( 'pdfprnt_archives', $pdfprnt_options['button_post_types']['print'], true ) );
680 } elseif ( $is_blog ) {
681 $show_button_pdf = ( in_array( 'pdfprnt_blog', $pdfprnt_options['button_post_types']['pdf'], true ) );
682 $show_button_print = ( in_array( 'pdfprnt_blog', $pdfprnt_options['button_post_types']['print'], true ) );
683 } else {
684 $show_button_pdf = false;
685 $show_button_print = false;
686 }
687
688 $loop_position = current_filter();
689 if ( ! ( $show_button_pdf || $show_button_print ) ) {
690 return;
691 }
692
693 if ( ( 'loop_start' === $loop_position && intval( $pdfprnt_show_archive_start ) === 1 ) || ( 'loop_end' === $loop_position && intval( $pdfprnt_show_archive_end ) === 1 ) ) {
694 return;
695 }
696
697 if ( $show_button_pdf || $show_button_print ) {
698 global $pdfprnt_is_search_archive;
699 $current_url = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? set_url_scheme( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : '';
700 $pdfprnt_is_search_archive = true;
701 $str = '<div class="pdfprnt-buttons pdfprnt-buttons-' . ( ( $is_search ) ? 'search' : 'archive' ) . ' pdfprnt-' . $pdfprnt_options['buttons_position'] . '">';
702 if ( $show_button_pdf ) {
703 $str .= pdfprnt_get_button( 'pdf', $current_url, 'pdf-search' );
704 add_action( 'wp_footer', 'pdfprnt_add_script' );
705 }
706
707 if ( $show_button_print ) {
708 $str .= pdfprnt_get_button( 'print', $current_url, 'print-search' );
709 }
710 $str .= '</div>';
711 echo wp_kses_post( $str );
712 if ( 'loop_start' === $loop_position ) {
713 $pdfprnt_show_archive_start++;
714 } elseif ( 'loop_end' === $loop_position ) {
715 $pdfprnt_show_archive_end++;
716 }
717 }
718 }
719 }
720 }
721
722 if ( ! function_exists( 'pdfprnt_return_buttons_search_archive' ) ) {
723 /**
724 * Return buttons for search or archive pages
725 */
726 function pdfprnt_return_buttons_search_archive() {
727 global $wp_query;
728
729 global $pdfprnt_options, $wp, $posts, $pdfprnt_show_archive_start, $pdfprnt_show_archive_end;
730
731 $is_search = ( is_search() );
732 $is_archive = ( is_archive() || is_category() || is_tax() || is_tag() || is_author() );
733 $is_blog = ( is_home() );
734
735 if ( $is_search ) {
736 $show_button_pdf = ( in_array( 'pdfprnt_search', $pdfprnt_options['button_post_types']['pdf'], true ) );
737 $show_button_print = ( in_array( 'pdfprnt_search', $pdfprnt_options['button_post_types']['print'], true ) );
738 } elseif ( $is_archive ) {
739 $show_button_pdf = ( in_array( 'pdfprnt_archives', $pdfprnt_options['button_post_types']['pdf'], true ) );
740 $show_button_print = ( in_array( 'pdfprnt_archives', $pdfprnt_options['button_post_types']['print'], true ) );
741 } elseif ( $is_blog ) {
742 $show_button_pdf = ( in_array( 'pdfprnt_blog', $pdfprnt_options['button_post_types']['pdf'], true ) );
743 $show_button_print = ( in_array( 'pdfprnt_blog', $pdfprnt_options['button_post_types']['print'], true ) );
744 } else {
745 $show_button_pdf = false;
746 $show_button_print = false;
747 }
748
749 $loop_position = current_filter();
750 if ( ! ( $show_button_pdf || $show_button_print ) ) {
751 return;
752 }
753
754 if ( ( 'loop_start' === $loop_position && intval( $pdfprnt_show_archive_start ) === 1 ) || ( 'loop_end' === $loop_position && intval( $pdfprnt_show_archive_end ) === 1 ) ) {
755 return;
756 }
757
758 if ( $show_button_pdf || $show_button_print ) {
759 global $pdfprnt_is_search_archive;
760 $current_url = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? set_url_scheme( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : '';
761 $pdfprnt_is_search_archive = true;
762 $str = '<div class="pdfprnt-buttons pdfprnt-buttons-' . ( ( $is_search ) ? 'search' : 'archive' ) . ' pdfprnt-' . $pdfprnt_options['buttons_position'] . '">';
763 if ( $show_button_pdf ) {
764 $str .= pdfprnt_get_button( 'pdf', $current_url );
765 add_action( 'wp_footer', 'pdfprnt_add_script' );
766 }
767
768 if ( $show_button_print ) {
769 $str .= pdfprnt_get_button( 'print', $current_url, 'print-search' );
770 }
771 $str .= '</div>';
772 if ( 'loop_start' === $loop_position ) {
773 $pdfprnt_show_archive_start++;
774 } elseif ( 'loop_end' === $loop_position ) {
775 $pdfprnt_show_archive_end++;
776 }
777 return $str;
778 }
779 }
780 }
781
782 if ( ! function_exists( 'pdfprnt_auto_show_buttons_search_archive' ) ) {
783 /**
784 * Add buttons before or after the loop
785 */
786 function pdfprnt_auto_show_buttons_search_archive() {
787 global $pdfprnt_options, $pdfprnt_is_old_php, $pdfprnt_plugin_info;
788 $check_page = false;
789 if ( $pdfprnt_is_old_php || apply_filters( 'pdfprnt_prevent_display_buttons', $check_page ) ) {
790 return;
791 }
792
793 $display_in_search = ( is_search() && ( in_array( 'pdfprnt_search', $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( 'pdfprnt_search', $pdfprnt_options['button_post_types']['print'], true ) ) );
794 $display_in_archive = ( ( is_archive() || is_category() || is_tax() || is_tag() || is_author() ) && ( in_array( 'pdfprnt_archives', $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( 'pdfprnt_archives', $pdfprnt_options['button_post_types']['print'], true ) ) );
795 $display_in_blog = ( ( is_home() ) && ( in_array( 'pdfprnt_blog', $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( 'pdfprnt_blog', $pdfprnt_options['button_post_types']['print'], true ) ) );
796
797 if ( $display_in_search || $display_in_archive || $display_in_blog ) {
798 global $pdfprnt_show_archive_start, $pdfprnt_show_archive_end;
799 $pdfprnt_show_archive_start = 0;
800 $pdfprnt_show_archive_end = 0;
801
802 $css = wp_remote_get( get_bloginfo( 'stylesheet_url' ) );
803
804 if ( is_array( $css ) && ! empty( $css['body'] ) && ( ! empty( mb_stristr( $css['body'], 'Twenty Twenty-Two', true ) ) || ! empty( mb_stristr( $css['body'], 'Twenty Twenty-Three', true ) ) ) ) {
805 $out1 = pdfprnt_return_buttons_search_archive();
806 if ( ! empty( $out1 ) ) {
807 wp_enqueue_script( 'pdfprnt_custom_script', plugins_url( 'js/custom_script.js', __FILE__ ), array( 'jquery' ), $pdfprnt_plugin_info['Version'], true );
808 }
809 }
810 if ( in_array( $pdfprnt_options['buttons_position'], array( 'top-left', 'top-right' ), true ) ) {
811 add_action( 'loop_start', 'pdfprnt_show_buttons_search_archive' );
812 if ( isset( $out1 ) && ! empty( $out1 ) ) {
813 wp_localize_script(
814 'pdfprnt_custom_script',
815 'pdfprnt_display_buttons',
816 array(
817 'top' => $out1,
818 )
819 );
820 }
821 } elseif ( in_array( $pdfprnt_options['buttons_position'], array( 'bottom-left', 'bottom-right' ), true ) ) {
822 add_action( 'loop_end', 'pdfprnt_show_buttons_search_archive' );
823 if ( isset( $out1 ) && ! empty( $out1 ) ) {
824 wp_localize_script(
825 'pdfprnt_custom_script',
826 'pdfprnt_display_buttons',
827 array(
828 'bottom' => $out1,
829 )
830 );
831 }
832 } else {
833 if ( isset( $out1 ) && ! empty( $out1 ) ) {
834 wp_localize_script(
835 'pdfprnt_custom_script',
836 'pdfprnt_display_buttons',
837 array(
838 'top' => $out1,
839 'bottom' => $out1,
840 )
841 );
842 }
843 add_action( 'loop_start', 'pdfprnt_show_buttons_search_archive' );
844 add_action( 'loop_end', 'pdfprnt_show_buttons_search_archive' );
845 }
846 }
847 }
848 }
849
850 if ( ! function_exists( 'pdfprnt_display_plugin_buttons' ) ) {
851 /**
852 * Display plugin buttons via action call
853 *
854 * @param string $where where to display.
855 * @param mixed $user_query WP_Query parameters.
856 */
857 function pdfprnt_display_plugin_buttons( $where = 'top', $user_query = '' ) {
858 global $pdfprnt_options, $pdfprnt_is_old_php;
859
860 if ( $pdfprnt_is_old_php ) {
861 return;
862 }
863
864 if ( preg_match( '|' . $where . '|', $pdfprnt_options['buttons_position'] ) || empty( $where ) ) {
865 echo wp_kses_post( pdfprnt_show_buttons_for_custom_post_type( $user_query ) );
866 }
867 }
868 }
869
870 if ( ! function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) {
871 /**
872 * Output buttons of page for custom post type
873 *
874 * @param string $user_query (Optional) User query.
875 * @return string $str
876 */
877 function pdfprnt_show_buttons_for_custom_post_type( $user_query = '' ) {
878 global $pdfprnt_options, $post, $posts;
879
880 $show_button_pdf = in_array( $post->post_type, $pdfprnt_options['button_post_types']['pdf'], true );
881 $show_button_print = in_array( $post->post_type, $pdfprnt_options['button_post_types']['print'], true );
882
883 $show_button_pdf = apply_filters( 'pdfprnt_show_buttons_for_custom_post_type', 'pdf', $show_button_pdf );
884 $show_button_print = apply_filters( 'pdfprnt_show_buttons_for_custom_post_type', 'print', $show_button_print );
885
886 if (
887 /* not display anything if displaying buttons for post and pages is disabled */
888 ( ! ( $show_button_pdf || $show_button_print ) ) ||
889 /* not display anything if we have wrong $user_query */
890 ( ! ( is_array( $user_query ) || is_string( $user_query ) ) )
891 ) {
892 return;
893 }
894 $current_url = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? set_url_scheme( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : '';
895 $current_url = esc_url( $current_url );
896 $is_return = true;
897
898 if ( empty( $user_query ) ) { /* set necessary values of parameters for pdf/print buttons */
899 $nothing_else = false;
900 if ( is_search() || is_archive() || is_category() || is_tax() || is_tag() || is_author() || ! pdfprnt_is_user_role_enabled() ) { /* search, cattegories, archives */
901 foreach ( $posts as $value ) {
902 if ( in_array( $value->post_type, $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( 'page', $pdfprnt_options['button_post_types']['print'], true ) ) {
903 $is_return = false;
904 break;
905 }
906 }
907 if ( $is_return ) {
908 return;
909 }
910 $pdf_query_parameter = 'pdf-search';
911 $print_query_parameter = 'print-search';
912 } elseif ( is_page() ) { /* pages */
913 if ( in_array( 'page', $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( 'page', $pdfprnt_options['button_post_types']['print'], true ) ) {
914 $nothing_else = true;
915 } else {
916 return;
917 }
918 } elseif ( is_single() ) { /* posts */
919 $post_type = get_post_type( $post->ID );
920 if ( in_array( $post_type, $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( $post_type, $pdfprnt_options['button_post_types']['print'], true ) ) {
921 $nothing_else = true;
922 } else {
923 return;
924 }
925 } else {
926 $nothing_else = true;
927 }
928 if ( $nothing_else ) {
929 $pdf_query_parameter = 'pdf';
930 $print_query_parameter = 'print';
931 }
932 } else {
933 $custom_query = new WP_Query( $user_query );
934 $current_url = add_query_arg( $custom_query->query, '', $current_url );
935 /* Check for existence the type of posts. */
936 if ( ! empty( $custom_query->posts ) ) {
937 foreach ( $custom_query->posts as $post ) {
938 if ( in_array( get_post_type( $post ), $pdfprnt_options['button_post_types']['pdf'], true ) || in_array( get_post_type( $post ), $pdfprnt_options['button_post_types']['print'], true ) ) {
939 $is_return = false;
940 break;
941 }
942 }
943 }
944 if ( $is_return ) {
945 return;
946 }
947 global $pdfprnt_is_custom_post_type;
948 $pdfprnt_is_custom_post_type = true;
949 $pdf_query_parameter = 'pdf-custom';
950 $print_query_parameter = 'print-custom';
951 }
952
953 $str = '<div class="pdfprnt-buttons pdfprnt-buttons-custom pdfprnt-buttons-' . $post->post_type . ' pdfprnt-' . $pdfprnt_options['buttons_position'] . '">';
954 $current_url = apply_filters( 'pdfprnt_current_url_filter', $current_url );
955 if ( $show_button_pdf ) {
956 $str .= pdfprnt_get_button( 'pdf', $current_url, $pdf_query_parameter );
957 add_action( 'wp_footer', 'pdfprnt_add_script' );
958 }
959 if ( $show_button_print ) {
960 $str .= pdfprnt_get_button( 'print', $current_url, $print_query_parameter );
961 }
962 $str .= '</div>';
963 return $str;
964 }
965 }
966
967 if ( ! function_exists( 'pdfprnt_action_links' ) ) {
968 /**
969 * Add action links
970 *
971 * @param array $links Links array.
972 * @param string $file Plugin file.
973 * @return array $links
974 */
975 function pdfprnt_action_links( $links, $file ) {
976 if ( ! is_network_admin() && is_plugin_inactive( 'pdf-print-pro/pdf-print-pro.php' ) ) {
977 $base = plugin_basename( __FILE__ );
978 if ( $file === $base ) {
979 $settings_link = '<a href="admin.php?page=pdf-print.php">' . esc_html__( 'Settings', 'pdf-print' ) . '</a>';
980 array_unshift( $links, $settings_link );
981 }
982 }
983 return $links;
984 }
985 }
986
987 if ( ! function_exists( 'pdfprnt_links' ) ) {
988 /**
989 * Add Settings, FAQ and Support links
990 *
991 * @param array $links Links array.
992 * @param string $file Plugin file.
993 * @return array $links
994 */
995 function pdfprnt_links( $links, $file ) {
996 $base = plugin_basename( __FILE__ );
997 if ( $file === $base ) {
998 if ( ! is_network_admin() && is_plugin_inactive( 'pdf-print-pro/pdf-print-pro.php' ) ) {
999 $links[] = '<a href="admin.php?page=pdf-print.php">' . esc_html__( 'Settings', 'pdf-print' ) . '</a>';
1000 }
1001 $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538669" target="_blank">' . esc_html__( 'FAQ', 'pdf-print' ) . '</a>';
1002 $links[] = '<a href="https://support.bestwebsoft.com">' . esc_html__( 'Support', 'pdf-print' ) . '</a>';
1003 }
1004 return $links;
1005 }
1006 }
1007
1008 if ( ! function_exists( 'pdfprnt_admin_head' ) ) {
1009 /**
1010 * Add stylesheets
1011 */
1012 function pdfprnt_admin_head() {
1013 global $pdfprnt_plugin_info, $pdfprnt_options, $post;
1014
1015 if ( is_admin() ) {
1016 wp_enqueue_style( 'pdfprnt_general', plugins_url( 'css/style-general.css', __FILE__ ), false, $pdfprnt_plugin_info['Version'] );
1017
1018 if ( isset( $_GET['page'] ) && 'pdf-print.php' === $_GET['page'] ) {
1019 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style.css', __FILE__ ), false, $pdfprnt_plugin_info['Version'] );
1020 bws_enqueue_settings_scripts();
1021 bws_plugins_include_codemirror();
1022 wp_enqueue_script( 'pdfprnt_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'jquery-ui-accordion', 'jquery-ui-slider' ), $pdfprnt_plugin_info['Version'], false );
1023 wp_localize_script(
1024 'pdfprnt_script',
1025 'pdfprnt_var',
1026 array(
1027 'loading_fonts' => esc_html__( 'Loading of fonts. It might take a several minutes.', 'pdf-print' ),
1028 'loading_mpdf' => esc_html__( 'Loading the mPDF library. It will take few minutes.', 'pdf-print' ),
1029 'ajax_nonce' => wp_create_nonce( 'pdfprnt_ajax_nonce' ),
1030 'need_reload' => '&nbsp;' . sprintf(
1031 esc_html__( 'It is necessary to reload fonts. For more info, please see %s.', 'pdf-print' ),
1032 '<a href="https://support.bestwebsoft.com/hc/en-us/articles/206693223" target="_blank">' . esc_html__( 'FAQ', 'pdf-print' ) . '</a>'
1033 ),
1034 )
1035 );
1036 }
1037 if ( isset( $_GET['page'] ) && 'pdf-print-templates.php' === $_GET['page'] ) {
1038 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/templates.css', __FILE__ ), false, $pdfprnt_plugin_info['Version'] );
1039 }
1040 } elseif ( isset( $post->post_title ) ) {
1041 wp_enqueue_style( 'pdfprnt_frontend', plugins_url( 'css/frontend.css', __FILE__ ), false, $pdfprnt_plugin_info['Version'] );
1042 }
1043 }
1044 }
1045
1046 if ( ! function_exists( 'pdfprnt_add_script' ) ) {
1047 /**
1048 * Sending data for front js
1049 */
1050 function pdfprnt_add_script() {
1051 global $pdfprnt_plugin_info , $post, $pdfprnt_options;
1052 if ( 1 === intval( $pdfprnt_options['image_to_pdf'] ) ) {
1053 $file_name = $post->post_title;
1054 wp_enqueue_script( 'html2canvas.js', plugins_url( 'js/html2canvas.js', __FILE__ ), array(), $pdfprnt_plugin_info['Version'], false );
1055 wp_enqueue_script( 'jspdf.js', plugins_url( 'js/jspdf.js', __FILE__ ), array(), $pdfprnt_plugin_info['Version'], false );
1056 wp_enqueue_script( 'pdfprnt_front_script', plugins_url( 'js/front-script.js', __FILE__ ), array( 'jquery', 'html2canvas.js', 'jspdf.js' ), $pdfprnt_plugin_info['Version'], false );
1057 wp_localize_script(
1058 'pdfprnt_front_script',
1059 'pdfprnt_file_settings',
1060 array(
1061 'margin_left' => $pdfprnt_options['pdf_margins']['left'],
1062 'margin_right' => $pdfprnt_options['pdf_margins']['right'],
1063 'margin_top' => $pdfprnt_options['pdf_margins']['top'],
1064 'margin_bottom' => $pdfprnt_options['pdf_margins']['bottom'],
1065 'page_size' => $pdfprnt_options['pdf_page_size'],
1066 'file_action' => $pdfprnt_options['file_action'],
1067 'file_name' => $file_name,
1068 )
1069 );
1070 }
1071 }
1072 }
1073
1074 if ( ! function_exists( 'pdfprnt_preg_replace' ) ) {
1075 /**
1076 * Remove inline 'font-family' and 'font' styles from content
1077 *
1078 * @param array $patterns Patterns array.
1079 * @param string $content Post content.
1080 * @return string $content
1081 */
1082 function pdfprnt_preg_replace( $patterns, $content ) {
1083 foreach ( $patterns as $pattern ) {
1084 $content = preg_replace( '/' . $pattern . '(.*?);/', '', $content );
1085 preg_match_all( "~style=(\"\'?)~", $content, $quotes );/* get array with quotes */
1086 if ( isset( $quotes[1] ) && ! empty( $quotes[1] ) ) {
1087 foreach ( $quotes[1] as $quote ) {
1088 preg_match_all( '~style=' . $quote . '(.*?)' . $quote . '~', $content, $styles );
1089 if ( ! empty( $styles[1] ) ) {
1090 foreach ( $styles[1] as $style ) {
1091 if ( preg_match( '/' . $pattern . '/', $style ) ) {
1092 $content = preg_replace( '/' . $style . '/', '', $content );
1093 }
1094 }
1095 }
1096 }
1097 }
1098 }
1099 return $content;
1100 }
1101 }
1102
1103 if ( ! function_exists( 'pdfprnt_generate_template' ) ) {
1104 /**
1105 * Generate templates for pdf file or print
1106 *
1107 * @param string $content Post content.
1108 * @param bool $is_print (Optional) Flag for print version.
1109 * @return string $html
1110 */
1111 function pdfprnt_generate_template( $content, $is_print = false ) {
1112 global $pdfprnt_options, $wp_locale, $post;
1113 $html =
1114 '<html>
1115 <head>';
1116 $html .= apply_filters( 'pdfprnt_add_meta_tag_robots', $html );
1117 if ( $is_print && $post instanceof WP_Post ) {
1118 if ( is_archive() || is_category() || is_tax() || is_tag() || is_author() || ! pdfprnt_is_user_role_enabled() ) {
1119 $title = ( function_exists( 'get_the_archive_title' ) ) ? get_the_archive_title() : wp_title( '', false );
1120 } elseif ( is_search() ) {
1121 $title = sprintf( esc_html__( 'Search Results for: %s', 'pdf-print' ), get_search_query() );
1122 } else {
1123 $title = get_the_title();
1124 }
1125 $html .= sprintf(
1126 '<title>%s - %s</title>',
1127 wp_strip_all_tags( $title ),
1128 get_bloginfo( 'name' )
1129 );
1130 }
1131 if ( ! empty( $pdfprnt_options['use_default_css'] ) && 1 === intval( $pdfprnt_options['use_default_css'] ) ) {
1132 /* remove 'font-family' and 'font' styles from theme css-file if additional fonts not loaded */
1133 if ( 0 === intval( $pdfprnt_options['additional_fonts'] ) ) {
1134 $css = wp_remote_get( get_bloginfo( 'stylesheet_url' ) );
1135 if ( is_array( $css ) && ! empty( $css['body'] ) ) {
1136 $html .= '<style type="text/css">' . preg_replace( '/(font:(.*?);)|(font-family(.*?);)/', '', $css['body'] ) . '</style>';
1137 }
1138 } else {
1139 $html .= '<link type="text/css" rel="stylesheet" href="' . get_bloginfo( 'stylesheet_url' ) . '" media="all" />';
1140 }
1141 } else {
1142 $html .= '<link type="text/css" rel="stylesheet" href="' . plugins_url( 'css/default.css', __FILE__ ) . '" media="all" />';
1143 }
1144 $html .= pdfprnt_additional_styles( $is_print );
1145 if ( 1 === intval( $pdfprnt_options['use_custom_css'] ) && ! empty( $pdfprnt_options['custom_css_code'] ) ) {
1146 $html .= '<style type="text/css">' . $pdfprnt_options['custom_css_code'] . '</style>';
1147 }
1148 if ( $is_print && 1 === intval( $pdfprnt_options['show_print_window'] ) ) {
1149 $html .= '<script>window.onload = function(){ window.print(); };</script>';
1150 }
1151 $html .= apply_filters( 'pdfprnt_woocommerce_layout', $html, $is_print );
1152 $html .=
1153 '</head>
1154 <body class="' . ( $is_print ? 'pdfprnt_print ' : '' ) . $wp_locale->text_direction . '">';
1155 /* Remove inline 'font-family' and 'font' styles from content */
1156 if ( 0 === intval( $pdfprnt_options['additional_fonts'] ) ) {
1157 $content = pdfprnt_preg_replace( array( 'font-family', 'font:' ), $content );
1158 }
1159 if ( function_exists( 'has_blocks' ) && has_blocks( $content ) ) {
1160 $content = preg_replace( '/\s?<!--.*-->\s?/', '', $content );
1161 $content = preg_replace( '~<p></p>~', '', $content );
1162 }
1163 $html .= $content .
1164 '</body>
1165 </html>';
1166 return $html;
1167 }
1168 }
1169
1170 if ( ! function_exists( 'pdfprnt_additional_styles' ) ) {
1171 /**
1172 * Additinal styles for plugin
1173 *
1174 * @param bool $is_print Flag for print version.
1175 * @return string $html
1176 */
1177 function pdfprnt_additional_styles( $is_print ) {
1178 $styles = apply_filters( 'bwsplgns_add_pdf_print_styles', array() );
1179 $html = '';
1180 if ( ! empty( $styles ) && is_array( $styles ) ) {
1181 $url = get_bloginfo( 'url' );
1182 require_once ABSPATH . 'wp-admin/includes/file.php';
1183 $path = get_home_path();
1184 foreach ( $styles as $style ) {
1185 if ( ! empty( $style[0] ) && file_exists( $path . $style[0] ) ) {
1186 /* if "get print" */
1187 if ( $is_print ) {
1188 if ( ( isset( $style[1] ) && 'print' === $style[1] ) || ! isset( $style[1] ) ) {
1189 $html .= '<link type="text/css" rel="stylesheet" href="' . $url . '/' . $style[0] . '" media="all" />';
1190 }
1191 /* if "get pdf" */
1192 } else {
1193 if ( ( isset( $style[1] ) && 'pdf' === $style[1] ) || ! isset( $style[1] ) ) {
1194 $html .= '<link type="text/css" rel="stylesheet" href="' . $url . '/' . $style[0] . '" media="all" />';
1195 }
1196 }
1197 }
1198 }
1199 }
1200 return $html;
1201 }
1202 }
1203
1204 if ( ! function_exists( 'pdfprnt_print' ) ) {
1205 /**
1206 * Output print page or pdf document and include plugin script
1207 *
1208 * @param string $query Query for post.
1209 */
1210 function pdfprnt_print( $query ) {
1211 global $pdfprnt_options, $posts, $post, $pdfprnt_is_old_php, $pdfprnt_links;
1212 $print = get_query_var( 'print' );
1213
1214 if ( $pdfprnt_is_old_php || empty( $print ) || ! pdfprnt_is_user_role_enabled() ) {
1215 return;
1216 }
1217
1218 if ( apply_filters( 'bwsplgns_remove_content_filters', true ) ) {
1219 remove_all_filters( 'the_content' );
1220 add_filter( 'the_content', 'capital_P_dangit', 11 );
1221 add_filter( 'the_content', 'wptexturize' );
1222 add_filter( 'the_content', 'convert_smilies' );
1223 add_filter( 'the_content', 'convert_chars' );
1224 add_filter( 'the_content', 'wpautop' );
1225
1226 if ( ! class_exists( 'WP_Embed' ) ) {
1227 require_once ABSPATH . WPINC . '/class-wp-embed.php';
1228 }
1229 new WP_Embed();
1230 }
1231 do_action( 'bwsplgns_pdf_print_the_content' );
1232 if ( 1 === intval( $pdfprnt_options['do_shorcodes'] ) ) {
1233 add_filter( 'the_content', 'do_shortcode' );
1234 $pattern = false;
1235 } else {
1236 $pattern = get_shortcode_regex();
1237 }
1238
1239 $doc_type = explode( '-', $print );
1240
1241 if ( ! is_array( $doc_type ) ) {
1242 return;
1243 }
1244
1245 /* for search or archives */
1246 if ( isset( $doc_type[1] ) ) {
1247 switch ( $doc_type[1] ) {
1248 case 'custom':
1249 $url_data = isset( $_SERVER['REQUEST_URI'] ) ? wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : array();
1250 parse_str( $url_data['query'], $args );
1251 unset( $args['print'] );
1252 if ( ! empty( $args ) ) {
1253 $posts = query_posts( $args );
1254 }
1255 break;
1256 case 'search':
1257 do_action( 'pdfprnt_rewrite_posts_woocommerce' );
1258 break;
1259 default:
1260 break;
1261 }
1262 /* for single posts or pages */
1263 } elseif (
1264 ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) === get_home_url() . '/?print=' . $doc_type[0]
1265 &&
1266 'page' === get_option( 'show_on_front' )
1267 ) {
1268 $post_id = get_option( 'page_on_front' );
1269 $posts = query_posts( array( 'page_id' => $post_id ) );
1270 } else {
1271 if ( ! is_home() ) {
1272 $posts = array( $post );
1273 }
1274 }
1275
1276 switch ( $doc_type[0] ) {
1277 case 'pdf':
1278 /* set path to directory with fonts */
1279 if ( ! ( 0 === intval( $pdfprnt_options['additional_fonts'] ) && defined( '_MPDF_SYSTEM_TTFONTS' ) ) ) {
1280 if ( is_multisite() ) {
1281 switch_to_blog( 1 );
1282 $upload_dir = wp_upload_dir();
1283 restore_current_blog();
1284 } else {
1285 $upload_dir = wp_upload_dir();
1286 }
1287 @define( '_MPDF_SYSTEM_TTFONTS', $upload_dir['basedir'] . '/pdf-print-fonts/' );
1288 }
1289
1290 /* prepare data */
1291 $titles = array();
1292 $authors = array();
1293 $default_font = 0 === intval( $pdfprnt_options['additional_fonts'] ) ? 'dejavusansmono' : '';
1294 $last = count( $posts );
1295 $i = 1;
1296 $html = '<div id="content">';
1297 foreach ( $posts as $p ) {
1298 if ( function_exists( 'et_theme_builder_get_template_layouts' ) && function_exists( 'et_theme_builder_frontend_render_header' ) ) {
1299 $layouts = et_theme_builder_get_template_layouts();
1300 ob_start();
1301 et_theme_builder_frontend_render_header(
1302 $layouts[ ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE ]['id'],
1303 $layouts[ ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE ]['enabled'],
1304 $layouts[ ET_THEME_BUILDER_TEMPLATE_POST_TYPE ]
1305 );
1306 $html .= ob_get_clean();
1307 }
1308 $title_filter = apply_filters( 'bwsplgns_get_pdf_print_title', apply_filters( 'the_title', $p->post_title, $p->ID ), $p );
1309 $titles[] = $title_filter;
1310 $user_info = get_userdata( $p->post_author );
1311 $authors[] = $user_info->display_name;
1312 $title = 1 === intval( $pdfprnt_options['show_title'] ) ? '<div class="entry-header"><h1 class="entry-title"><a href="' . get_permalink( $p ) . '">' . $title_filter . '</a></h1></div>' : '';
1313 $image = 1 === intval( $pdfprnt_options['show_featured_image'] ) && has_post_thumbnail( $p->ID ) ? '<div class="entry-thumbnail">' . get_the_post_thumbnail( $p->ID, $pdfprnt_options['featured_image_size'] ) . '</div>' : '';
1314 $date = 1 === intval( $pdfprnt_options['show_date'] ) ? '<span class="entry-date">' . get_the_date( get_option( 'date_format' ) ) . '</span>' : '';
1315 $author = 1 === intval( $pdfprnt_options['show_author'] ) ? '<span class="entry-author">' . esc_html__( 'written by', 'pdf-print' ) . ' ' . get_the_author_meta( 'display_name', $p->post_author ) . '</span>' : '';
1316 $category = 1 === intval( $pdfprnt_options['show_category'] ) && has_category( '', $p->ID ) ? '<div class="entry-category">' . __( 'Category', 'pdf-print-pro' ) . ': ' . implode( ',', wp_get_post_categories( $p->ID, array( 'fields' => 'names' ) ) ) . '</div>' : '';
1317 /* replacing shortcodes to an empty string which were added to the content */
1318 if ( $pattern && preg_match_all( '/' . $pattern . '/s', $p->post_content, $matches ) ) {
1319 foreach ( array_unique( $matches[0] ) as $value ) {
1320 $p->post_content = str_replace( $value, '', $p->post_content );
1321 }
1322 }
1323 if ( 1 === intval( $pdfprnt_options['remove_links'] ) ) {
1324 $p->post_content = preg_replace( '~<a\b[^>]*+>|</a\b[^>]*+>~', '$2', $p->post_content );
1325 $p->post_content = preg_replace( '@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '', $p->post_content );
1326 }
1327 if ( 1 === intval( $pdfprnt_options['disable_links'] ) ) {
1328 $html .= '<style> a {text-decoration: none; color:#000000 !important; } </style>';
1329 }
1330
1331 $post_visible = ( ! empty( $p->post_excerpt ) && ! is_singular() ) ? $p->post_excerpt : $p->post_content;
1332 $post_content = apply_filters( 'bwsplgns_get_pdf_print_content', $post_visible, $p );
1333 $shortcodes = implode( '|', apply_filters( 'bwsplgns_pdf_print_remove_shortcodes', array( 'vc_', 'az_', 'multilanguage_switcher' ) ) );
1334 $post_content = preg_replace( "/\[\/?({$shortcodes})[^\]]*?\]/", '', $post_content );
1335 $post_content = apply_filters( 'the_content', $post_content );
1336 $post_content = apply_filters( 'bwsplgns_pdf_customize_content', $post_content );
1337 $separator = '';
1338 if ( ! empty( $author ) && ! empty( $date ) ) {
1339 $separator = ' | ';
1340 }
1341 $html .=
1342 '<div class="post">' .
1343 $title .
1344 $category .
1345 '<div class="postmetadata">' . $author . $separator . $date . '</div>' .
1346 $image .
1347 '<div class="entry-content">' . $post_content . '</div>
1348 </div>';
1349 if ( $i !== $last ) {
1350 $html .= '<br/><hr/><br/>';
1351 $i ++;
1352 }
1353 }
1354 if ( function_exists( 'et_theme_builder_get_template_layouts' ) && function_exists( 'et_theme_builder_frontend_render_footer' ) ) {
1355 ob_start();
1356 et_theme_builder_frontend_render_footer(
1357 $layouts[ ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE ]['id'],
1358 $layouts[ ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE ]['enabled'],
1359 $layouts[ ET_THEME_BUILDER_TEMPLATE_POST_TYPE ]
1360 );
1361 $html .= ob_get_clean();
1362 }
1363 $html .= '</div>';
1364 $titles = array_unique( $titles );
1365 $authors = array_unique( $authors );
1366
1367 $pdfprnt_links = $pdfprnt_options['disable_links'];
1368
1369 /* generate PDF-document */
1370 $path = $upload_dir['basedir'] . '/vendor/mpdf';
1371 $is_installed = file_exists( $path );
1372 if ( $is_installed ) {
1373 /* Implement mPDF v7.1.5 */
1374 if ( ! class_exists( '\Mpdf\Mpdf' ) ) {
1375 include $upload_dir['basedir'] . '/vendor/autoload.php';
1376 }
1377 $mpdf_config = array(
1378 'mode' => '+aCJK',
1379 'format' => $pdfprnt_options['pdf_page_size'],
1380 'default_font_size' => 0,
1381 'default_font' => $default_font,
1382 'margin_left' => $pdfprnt_options['pdf_margins']['left'],
1383 'margin_right' => $pdfprnt_options['pdf_margins']['right'],
1384 'margin_top' => $pdfprnt_options['pdf_margins']['top'],
1385 'margin_bottom' => $pdfprnt_options['pdf_margins']['bottom'],
1386 );
1387 $mpdf = new \Mpdf\Mpdf( $mpdf_config );
1388
1389 } else {
1390 include dirname( __FILE__ ) . '/mpdf/mpdf.php';
1391 $mpdf = new mPDF(
1392 '+aCJK',
1393 $pdfprnt_options['pdf_page_size'],
1394 0,
1395 $default_font,
1396 $pdfprnt_options['pdf_margins']['left'],
1397 $pdfprnt_options['pdf_margins']['right'],
1398 $pdfprnt_options['pdf_margins']['top'],
1399 $pdfprnt_options['pdf_margins']['bottom']
1400 );
1401 }
1402 $mpdf->allow_charset_conversion = true;
1403 $mpdf->charset_in = get_bloginfo( 'charset' );
1404 if ( 0 !== intval( $pdfprnt_options['additional_fonts'] ) ) {
1405 $mpdf->autoScriptToLang = true;
1406 $mpdf->autoLangToFont = true;
1407 $mpdf->baseScript = 1;
1408 $mpdf->autoVietnamese = true;
1409 $mpdf->autoArabic = true;
1410 }
1411 if ( is_rtl() ) {
1412 $mpdf->SetDirectionality( 'rtl' );
1413 }
1414 $mpdf->SetTitle( htmlspecialchars_decode( implode( ',', $titles ) ) );
1415 $mpdf->SetAuthor( implode( ',', $authors ) );
1416 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1417 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
1418 do_action_ref_array( 'bwsplgns_mpdf', array( &$mpdf ) );
1419 if ( 'download' === $pdfprnt_options['file_action'] ) {
1420 $mpdf->Output( '', 'D' );
1421 } else {
1422 $mpdf->Output();
1423 }
1424 die();
1425 break;
1426 case 'print':
1427 $last = count( $posts );
1428 $i = 1;
1429 $html = '<div id="content">';
1430 foreach ( $posts as $p ) {
1431 if ( function_exists( 'et_theme_builder_get_template_layouts' ) && function_exists( 'et_theme_builder_frontend_render_header' ) ) {
1432 $layouts = et_theme_builder_get_template_layouts();
1433 ob_start();
1434 et_theme_builder_frontend_render_header(
1435 $layouts[ ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE ]['id'],
1436 $layouts[ ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE ]['enabled'],
1437 $layouts[ ET_THEME_BUILDER_TEMPLATE_POST_TYPE ]
1438 );
1439 $html .= ob_get_clean();
1440 }
1441
1442 $title = 1 === intval( $pdfprnt_options['show_title'] ) ? '<div class="entry-header"><h1 class="entry-title">' . apply_filters( 'bwsplgns_get_pdf_print_title', apply_filters( 'the_title', $p->post_title, $p->ID ), $p ) . '</h1></div>' : '';
1443 $image = 1 === intval( $pdfprnt_options['show_featured_image'] ) && has_post_thumbnail( $p->ID ) ? '<div class="entry-thumbnail">' . get_the_post_thumbnail( $p->ID, $pdfprnt_options['featured_image_size'] ) . '</div>' : '';
1444 $date = 1 === intval( $pdfprnt_options['show_date'] ) ? '<span class="entry-date">' . get_the_date( get_option( 'date_format' ) ) . '</span>' : '';
1445 $author = 1 === intval( $pdfprnt_options['show_author'] ) ? '<span class="entry-author">' . esc_html__( 'written by', 'pdf-print' ) . ' ' . get_the_author_meta( 'display_name', $p->post_author ) . '</span>' : '';
1446 $category = 1 === intval( $pdfprnt_options['show_category'] ) && has_category( '', $p->ID ) ? '<div class="entry-category">' . __( 'Category', 'pdf-print-pro' ) . ': ' . implode( ',', wp_get_post_categories( $p->ID, array( 'fields' => 'names' ) ) ) . '</div>' : '';
1447 /* replacing shortcodes to an empty string which were added to the content */
1448 if ( $pattern && preg_match_all( '/' . $pattern . '/s', $p->post_content, $matches ) ) {
1449 foreach ( array_unique( $matches[0] ) as $value ) {
1450 $p->post_content = str_replace( $value, '', $p->post_content );
1451 }
1452 }
1453 if ( 1 === intval( $pdfprnt_options['remove_links'] ) ) {
1454 $p->post_content = preg_replace( '~<a\b[^>]*+>|</a\b[^>]*+>~', '$2', $p->post_content );
1455 $p->post_content = preg_replace( '@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '', $p->post_content );
1456 }
1457 if ( 1 === intval( $pdfprnt_options['disable_links'] ) ) {
1458 $html .= '<style> a {text-decoration: none; color:#000000 !important; } </style>';
1459 }
1460
1461 $post_content = apply_filters( 'bwsplgns_get_pdf_print_content', $p->post_content, $p );
1462 $shortcodes = implode( '|', apply_filters( 'bwsplgns_pdf_print_remove_shortcodes', array( 'vc_', 'az_', 'multilanguage_switcher' ) ) );
1463 $post_content = preg_replace( "/\[\/?({$shortcodes})[^\]]*?\]/", '', $post_content );
1464 $post_content = apply_filters( 'the_content', $post_content );
1465
1466 $separator = '';
1467
1468 if ( ! empty( $author ) && ! empty( $date ) ) {
1469 $separator = ' | ';
1470 }
1471
1472 ob_start();
1473 ?>
1474 <div class="post">
1475 <?php
1476 echo wp_kses_post( $title ) .
1477 wp_kses_post( $category ) .
1478 '<div class="postmetadata">' . wp_kses_post( $author . $separator . $date ) . '</div>' .
1479 wp_kses_post( $image );
1480 ?>
1481 <div class="entry-content"><?php echo wp_kses_post( $post_content ); ?></div>
1482 </div>
1483 <?php
1484 $html .= ob_get_clean();
1485 if ( $i !== $last ) {
1486 $html .= '<br/><hr/><br/>';
1487 $i ++;
1488 }
1489 }
1490 if ( function_exists( 'et_theme_builder_get_template_layouts' ) && function_exists( 'et_theme_builder_frontend_render_footer' ) ) {
1491 ob_start();
1492 et_theme_builder_frontend_render_footer(
1493 $layouts[ ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE ]['id'],
1494 $layouts[ ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE ]['enabled'],
1495 $layouts[ ET_THEME_BUILDER_TEMPLATE_POST_TYPE ]
1496 );
1497 $html .= ob_get_clean();
1498 }
1499 $html .= '</div>';
1500 echo pdfprnt_generate_template( $html, true );
1501 die();
1502 default:
1503 break;
1504 }
1505 }
1506 }
1507
1508 if ( ! function_exists( 'pdfprnt_print_vars_callback' ) ) {
1509 /**
1510 * Add query vars
1511 *
1512 * @param array $query_vars Query vars array.
1513 */
1514 function pdfprnt_print_vars_callback( $query_vars ) {
1515 $query_vars[] = 'print';
1516 return $query_vars;
1517 }
1518 }
1519
1520 if ( class_exists( 'ZipArchive' ) && ! class_exists( 'Pdfprnt_ZipArchive' ) ) {
1521 /**
1522 * Class Pdfprnt_ZipArchive for extracting
1523 * necessary folder from zip-archive
1524 */
1525 class Pdfprnt_ZipArchive extends ZipArchive {
1526 /**
1527 * Constructor of class
1528 *
1529 * @param string $destination Directory for zip.
1530 * @param string $subdir Subdirectory for zip.
1531 */
1532 public function extractSubdirTo( $destination, $subdir ) {
1533 $errors = array();
1534 $charset = get_bloginfo( 'charset' );
1535 /* Prepare dirs */
1536 $destination = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $destination );
1537 $subdir = str_replace( array( '/', '\\' ), '/', $subdir );
1538
1539 if ( substr( $destination, mb_strlen( DIRECTORY_SEPARATOR, $charset ) * -1 ) !== DIRECTORY_SEPARATOR ) {
1540 $destination .= DIRECTORY_SEPARATOR;
1541 }
1542
1543 if ( substr( $subdir, -1 ) !== '/' ) {
1544 $subdir .= '/';
1545 }
1546 /* Extract files */
1547 for ( $i = 0; $i < $this->numFiles; $i++ ) {
1548 $filename = $this->getNameIndex( $i );
1549
1550 if ( substr( $filename, 0, mb_strlen( $subdir, $charset ) ) === $subdir ) {
1551 $relative_path = substr( $filename, mb_strlen( $subdir, $charset ) );
1552 $relative_path = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $relative_path );
1553
1554 if ( mb_strlen( $relative_path, $charset ) > 0 ) {
1555 if ( substr( $filename, -1 ) === '/' ) {
1556 if ( ! is_dir( $destination . $relative_path ) ) {
1557 if ( ! @mkdir( $destination . $relative_path, 0755, true ) ) {
1558 $errors[ $i ] = $filename;
1559 }
1560 }
1561 } else {
1562 if ( dirname( $relative_path ) !== '.' ) {
1563 if ( ! is_dir( $destination . dirname( $relative_path ) ) ) {
1564 /* New dir (for file) */
1565 @mkdir( $destination . dirname( $relative_path ), 0755, true );
1566 }
1567 }
1568 /* New file */
1569 if ( @file_put_contents( $destination . $relative_path, $this->getFromIndex( $i ) ) === false ) {
1570 $errors[ $i ] = $filename;
1571 }
1572 }
1573 }
1574 }
1575 }
1576 return $errors;
1577 }
1578 }
1579 }
1580
1581 if ( ! function_exists( 'pdfprnt_download_zip' ) ) {
1582 /**
1583 * Download Zip
1584 *
1585 * @param array $zip_file Zip file name.
1586 * @param array $upload_dir Path for upload directory.
1587 * @param array $url Url for Curl.
1588 * @return array $result
1589 */
1590 function pdfprnt_download_zip( $zip_file, $upload_dir, $url ) {
1591 /* Check permissions */
1592 if ( is_writable( $upload_dir ) ) {
1593 /* Load ZIP-archive */
1594 $result = array();
1595 $fp = fopen( $zip_file, 'w+' );
1596 /* File size is too big to use wp_remote_get function */
1597 $curl = curl_init();
1598 $curl_parametres = array(
1599 CURLOPT_URL => $url,
1600 CURLOPT_FILE => $fp,
1601 CURLOPT_USERAGENT => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0' ),
1602 );
1603 curl_setopt_array( $curl, $curl_parametres );
1604 if ( curl_exec( $curl ) ) {
1605 $result['done'] = 'ok';
1606 } else {
1607 $result['error'] = curl_error( $curl ) . '<br />' . esc_html__( 'Check your internet connection', 'pdf-print' );
1608 }
1609 curl_close( $curl );
1610 fclose( $fp );
1611 } else {
1612 $result['error'] = esc_html__( 'Cannot load files in to "uploads" folder. Check your permissions', 'pdf-print' );
1613 }
1614 return $result;
1615 }
1616 }
1617
1618 if ( ! function_exists( 'pdfprnt_copy_fonts' ) ) {
1619 /**
1620 * Extract additional fonts to uploads/pdf-print-fonts
1621 *
1622 * @param string $zip_file Path to zip archive.
1623 * @param string $upload_dir Name for zip archive.
1624 */
1625 function pdfprnt_copy_fonts( $zip_file, $upload_dir ) {
1626 global $pdfprnt_options;
1627 if ( empty( $pdfprnt_options ) ) {
1628 $pdfprnt_options = get_option( 'pdfprnt_options' );
1629 }
1630 $destination = $upload_dir . '/pdf-print-fonts';
1631 if ( ! file_exists( $destination ) ) {
1632 mkdir( $destination, 0755, true );
1633 }
1634 $result = array();
1635 /* check permissions */
1636 if ( is_writable( $destination ) ) {
1637 $zip = new Pdfprnt_ZipArchive();
1638 /* open zip-archive */
1639 if ( true === $zip->open( $zip_file ) ) {
1640 /* extract folder with fonts */
1641 $errors = $zip->extractSubdirTo( $destination, 'mpdf-master/ttfonts' );
1642 $zip->close();
1643 if ( empty( $errors ) ) {
1644 $result['done'] = esc_html__( 'Additional fonts were loaded successfully.', 'pdf-print' );
1645 unlink( $zip_file );
1646 } else {
1647 $result['error'] = esc_html__( 'Some errors occurred during loading files.', 'pdf-print' );
1648 }
1649 } else {
1650 $result['error'] = esc_html__( 'Can not extract files from zip-archive.', 'pdf-print' );
1651 unlink( $zip_file );
1652 }
1653 } else {
1654 $result['error'] = sprintf( esc_html__( 'Cannot create %s folder. Check your permissions.', 'pdf-print' ), '"uploads/pdf-print-fonts"' );
1655 }
1656 $files = scandir( $destination );
1657 $value = isset( $result['error'] ) ? -1 : count( $files );
1658 $opt = 'additional_fonts';
1659 pdfprnt_update_option( $opt, $value, true );
1660 return $result;
1661 }
1662 }
1663
1664
1665 if ( ! function_exists( 'pdfprnt_extract_mpdf_library' ) ) {
1666 /**
1667 * Extract mPDF library ( verson 7.1.5 ) from zip-archive
1668 *
1669 * @param string $zip_file Path to zip-archive.
1670 * @param string $upload_dir Path to "Upload" folder.
1671 * @return string $result Result message.
1672 */
1673 function pdfprnt_extract_mpdf_library( $zip_file, $upload_dir ) {
1674 global $wpdb;
1675
1676 $result = array();
1677 /* check permissions */
1678 if ( is_writable( $upload_dir ) ) {
1679 $zip = new Pdfprnt_ZipArchive();
1680 /* open zip-archive */
1681 if ( true === $zip->open( $zip_file ) ) {
1682 /* extract folder with fonts */
1683 $errors = $zip->extractSubdirTo( $upload_dir, 'mpdf' );
1684 $zip->close();
1685 if ( empty( $errors ) ) {
1686 $options_default = pdfprnt_get_options_default();
1687 $value = $options_default['mpdf_library_version'];
1688 $result['done'] = esc_html__( 'The mPDF library has been loaded successfully.', 'pdf-print' );
1689 unlink( $zip_file );
1690 } else {
1691 $result['error'] = esc_html__( 'Some errors occurred during loading files.', 'pdf-print' );
1692 }
1693 } else {
1694 $result['error'] = esc_html__( 'Can not extract files from zip-archive.', 'pdf-print' );
1695 unlink( $zip_file );
1696 }
1697 } else {
1698 $result['error'] = sprintf( esc_html__( 'Cannot extract files into %s folder. Check your permissions.', 'pdf-print' ), $upload_dir );
1699 }
1700 if ( ! isset( $value ) ) {
1701 $value = '6.1';
1702 }
1703
1704 $opt = 'mpdf_library_version';
1705 pdfprnt_update_option( $opt, $value, true );
1706 return $result;
1707 }
1708 }
1709
1710 if ( ! function_exists( 'pdfprnt_load_and_copy' ) ) {
1711 /**
1712 * Download ZIP-archive with MPDF library,
1713 * copy fonts to folder 'pdf-print-fons'
1714 *
1715 * @param string $zip_file path to zip-archive.
1716 * @param string $upload_dir path to "Upload" folder.
1717 * @param boolean $url url for archive.
1718 * @param boolean $old_dir old dir for archive.
1719 * @return string $result result message.
1720 */
1721 function pdfprnt_load_and_copy( $zip_file, $upload_dir, $url, $old_dir = '' ) {
1722 $result = file_exists( $zip_file ) ? array( 'done' => 'ok' ) : pdfprnt_download_zip( $zip_file, $upload_dir, $url );
1723 if ( is_multisite() ) {
1724 switch_to_blog( 1 );
1725 $dir = wp_upload_dir();
1726 restore_current_blog();
1727 } else {
1728 $dir = wp_upload_dir();
1729 }
1730 if ( ! empty( $old_dir ) && plugin_dir_path( __FILE__ ) . 'mpdf' === $old_dir && isset( $result['done'] ) ) {
1731 $result = pdfprnt_extract_mpdf_library( $zip_file, $upload_dir );
1732 } elseif ( isset( $result['done'] ) ) {
1733 $result = pdfprnt_copy_fonts( $zip_file, $upload_dir );
1734 }
1735 return $result;
1736 }
1737 }
1738
1739
1740 if ( ! function_exists( 'pdfprnt_load_fonts' ) ) {
1741 /**
1742 * Function to load fonts for MPDF library
1743 */
1744 function pdfprnt_load_fonts() {
1745 global $pdfprnt_options;
1746 if ( empty( $pdfprnt_options ) ) {
1747 $pdfprnt_options = get_option( 'pdfprnt_options' );
1748 }
1749 $ajax_request = isset( $_REQUEST['action'] ) && 'pdfprnt_load_fonts' === sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ? true : false;
1750 $php_request = isset( $_REQUEST['pdfprnt_action'] ) && 'pdfprnt_load_fonts' === sanitize_text_field( wp_unslash( $_REQUEST['pdfprnt_action'] ) ) ? true : false;
1751 $verified = isset( $_REQUEST['pdfprnt_ajax_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['pdfprnt_ajax_nonce'] ) ), 'pdfprnt_ajax_nonce' ) ? true : false;
1752 /* Sourse of the fonts */
1753 $url = 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/fontdownloads/?action=loading_fonts';
1754 if ( ( $ajax_request || $php_request ) && $verified ) {
1755 $result = array();
1756 $flag = false;
1757 /* get path to directory for ZIP-archive uploading */
1758 if ( is_multisite() ) {
1759 switch_to_blog( 1 );
1760 $upload_dir = wp_upload_dir();
1761 restore_current_blog();
1762 } else {
1763 $upload_dir = wp_upload_dir();
1764 }
1765 $zip_file = $upload_dir['basedir'] . '/mpdf-master.zip';
1766 $destination = $upload_dir['basedir'] . '/pdf-print-fonts';
1767 if ( file_exists( $destination ) ) { /* if folder with fonts already exists */
1768 if ( is_multisite() ) {
1769 $network_options = get_site_option( 'pdfprnt_options' ); /* get network options */
1770 $files = scandir( $destination );
1771 if ( intval( $network_options['additional_fonts'] ) === count( $files ) ) { /* if all fonts was loaded successfully */
1772 $result['done'] = esc_html__( 'Additional fonts were loaded successfully.', 'pdf-print' );
1773 $opt = 'additional_fonts';
1774 pdfprnt_update_option( $opt, $network_options['additional_fonts'], true );
1775 } else { /* if something wrong */
1776 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'], $url ); /* load fonts */
1777 }
1778 } else {
1779 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'], $url ); /* load fonts */
1780 }
1781 } else {
1782 mkdir( $destination, 0755, true );
1783 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'], $url );
1784 }
1785 if ( $ajax_request ) {
1786 echo wp_json_encode( $result );
1787 } else {
1788 return $result;
1789 }
1790 }
1791 if ( $ajax_request ) {
1792 die();
1793 }
1794 }
1795 }
1796
1797 if ( ! function_exists( 'pdfprnt_upgrade_library' ) ) {
1798 /**
1799 * Function to upgrade the MPDF library from version 6.1 to verson 7.1.5
1800 *
1801 * @return string $result result message
1802 */
1803 function pdfprnt_upgrade_library() {
1804 global $pdfprnt_options, $wpdb;
1805
1806 $ajax_request = isset( $_REQUEST['action'] ) && 'pdfprnt_upgrade_library' === $_REQUEST['action'] ? true : false;
1807
1808 $php_request = isset( $_REQUEST['pdfprnt_action'] ) && 'pdfprnt_upgrade_library' === sanitize_text_field( wp_unslash( $_REQUEST['pdfprnt_action'] ) ) ? true : false;
1809 $verified = isset( $_REQUEST['pdfprnt_ajax_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['pdfprnt_ajax_nonce'] ) ), 'pdfprnt_ajax_nonce' ) ? true : false;
1810 $old_dir = plugin_dir_path( __FILE__ ) . 'mpdf';
1811 $result = array();
1812 if ( ( $ajax_request || $php_request ) && true === $verified ) {
1813 /* get path to directory for ZIP-archive uploading */
1814 if ( is_multisite() ) {
1815 switch_to_blog( 1 );
1816 $upload_dir = wp_upload_dir();
1817 restore_current_blog();
1818 } else {
1819 $upload_dir = wp_upload_dir();
1820 }
1821 $zip_file = $upload_dir['basedir'] . '/mpdf.zip';
1822
1823 /* Sourse of the MPDF library */
1824 $url = 'https://bestwebsoft.com/wp-content/plugins/paid-products/plugins/pdf-print-mpdf/?action=loading_library';
1825 $new_dir = $upload_dir['basedir'] . '/vendor';
1826
1827 if ( ! file_exists( $new_dir ) ) {
1828 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'], $url, $old_dir ); /* load library */
1829 }
1830 if ( ! isset( $result['error'] ) ) {
1831 pdfprnt_delete_old_library( $old_dir );
1832 }
1833 }
1834 if ( true === $ajax_request ) {
1835 echo wp_json_encode( $result );
1836 wp_die();
1837 } else {
1838 return $result;
1839 }
1840 }
1841 }
1842
1843 if ( ! function_exists( 'pdfprnt_delete_old_library' ) ) {
1844 /**
1845 * Delete old library
1846 *
1847 * @param string $dir path to library dir.
1848 * @return bool resullt removing dir.
1849 */
1850 function pdfprnt_delete_old_library( $dir ) {
1851 $files = scandir( $dir );
1852 $files = array_diff( $files, array( '.', '..' ) );
1853 foreach ( $files as $file ) {
1854 ( is_dir( "$dir/$file" ) ) ? pdfprnt_delete_old_library( "$dir/$file" ) : unlink( "$dir/$file" );
1855 }
1856 return rmdir( $dir );
1857 }
1858 }
1859
1860 if ( ! function_exists( 'pdfprnt_update_option' ) ) {
1861 /**
1862 * Update options
1863 *
1864 * @param string $opt option slug.
1865 * @param string $value new value.
1866 * @param bool $update_network (Optional) flag for update network.
1867 */
1868 function pdfprnt_update_option( $opt, $value, $update_network = false ) {
1869 global $pdfprnt_options;
1870 if ( empty( $pdfprnt_options ) ) {
1871 $pdfprnt_options = get_option( 'pdfprnt_options' );
1872 }
1873 $pdfprnt_options[ $opt ] = $value;
1874 update_option( 'pdfprnt_options', $pdfprnt_options );
1875 if ( $update_network ) {
1876 $network_options = get_site_option( 'pdfprnt_options' );
1877 $network_options[ $opt ] = $value;
1878 update_site_option( 'pdfprnt_options', $network_options );
1879 }
1880 }
1881 }
1882
1883 if ( ! function_exists( 'pdfprnt_get_pdf_page_sizes' ) ) {
1884 /**
1885 * Pafe sizes array
1886 */
1887 function pdfprnt_get_pdf_page_sizes() {
1888 $page_sizes = array(
1889 'A0',
1890 'A1',
1891 'A2',
1892 'A3',
1893 'A4',
1894 'A5',
1895 'A6',
1896 'A7',
1897 'A8',
1898 'A9',
1899 'A10',
1900 'B0',
1901 'B1',
1902 'B2',
1903 'B3',
1904 'B4',
1905 'B5',
1906 'B6',
1907 'B7',
1908 'B8',
1909 'B9',
1910 'B10',
1911 'C0',
1912 'C1',
1913 'C2',
1914 'C3',
1915 'C4',
1916 'C5',
1917 'C6',
1918 'C7',
1919 'C8',
1920 'C9',
1921 'C10',
1922 '4A0',
1923 '2A0',
1924 'RA0',
1925 'RA1',
1926 'RA2',
1927 'RA3',
1928 'RA4',
1929 'SRA0',
1930 'SRA1',
1931 'SRA2',
1932 'SRA3',
1933 'SRA4',
1934 'Letter',
1935 'Legal',
1936 'Executive',
1937 'Folio',
1938 'Demy',
1939 'Royal',
1940 'A',
1941 'B',
1942 );
1943 $page_sizes = apply_filters( 'pdfprnt_get_pdf_page_sizes', $page_sizes );
1944 return $page_sizes;
1945 }
1946 }
1947
1948 if ( ! function_exists( 'pdfprnt_plugin_banner' ) ) {
1949 /**
1950 * Display plugn banner
1951 */
1952 function pdfprnt_plugin_banner() {
1953 global $hook_suffix, $pdfprnt_plugin_info;
1954 if ( 'plugins.php' === $hook_suffix ) {
1955 bws_plugin_banner_to_settings( $pdfprnt_plugin_info, 'pdfprnt_options', 'pdf-print', 'admin.php?page=pdf-print.php' );
1956 if ( function_exists( 'bws_plugin_banner_to_promo' ) ) {
1957 bws_plugin_banner_to_promo( $pdfprnt_plugin_info, 'pdfprnt_options', 'pdf-print', 'admin.php?page=pdf-print.php', array( __( 'Test your PDF Generation Settings', 'bestwebsoft' ), __( "Ensure your PDF & Print plugin is correctly configured. Check your settings now!", 'bestwebsoft' ) ) );
1958 }
1959
1960 if ( isset( $_REQUEST['page'] ) && 'pdf-print.php' === $_REQUEST['page'] ) {
1961 bws_plugin_suggest_feature_banner( $pdfprnt_plugin_info, 'pdfprnt_options', 'pdf-print' );
1962 }
1963 }
1964 }
1965 }
1966
1967 if ( ! function_exists( 'pdfprnt_register_buttons_widget' ) ) {
1968 /**
1969 * Register buttons Widget
1970 */
1971 function pdfprnt_register_buttons_widget() {
1972 global $pdfprnt_is_old_php;
1973 if ( ! $pdfprnt_is_old_php ) {
1974 if ( ! class_exists( 'Pdfprnt_Buttons_Widget' ) ) {
1975 require_once dirname( __FILE__ ) . '/includes/class-pdfprnt-buttons-widget.php';
1976 }
1977 register_widget( 'Pdfprnt_Buttons_Widget' );
1978 }
1979 }
1980 }
1981
1982
1983 if ( ! function_exists( 'pdfprnt_uninstall' ) ) {
1984 /**
1985 * Deleting plugin options on uninstalling
1986 */
1987 function pdfprnt_uninstall() {
1988 if ( ! function_exists( 'get_plugins' ) ) {
1989 require_once ABSPATH . 'wp-admin/includes/plugin.php';
1990 }
1991 $all_plugins = get_plugins();
1992
1993 if ( ! array_key_exists( 'pdf-print-pro/pdf-print-pro.php' /*pls */ && ! array_key_exists( 'pdf-print-plus/pdf-print-plus.php', $all_plugins )/* pls*/, $all_plugins ) ) {
1994 global $wpdb;
1995 if ( is_multisite() ) {
1996 /* Get all blog ids */
1997 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1998 $tables = '';
1999 $old_blog = $wpdb->blogid;
2000 foreach ( $blogids as $blog_id ) {
2001 switch_to_blog( $blog_id );
2002 delete_option( 'pdfprnt_options' );
2003 delete_option( 'widget_pdfprint_buttons' );
2004 }
2005 switch_to_blog( $old_blog );
2006 delete_site_option( 'pdfprnt_options' );
2007 delete_option( 'widget_pdfprnt_buttons' );
2008 } else {
2009 delete_option( 'pdfprnt_options' );
2010 delete_option( 'widget_pdfprnt_buttons' );
2011 }
2012 }
2013
2014 require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php';
2015 bws_include_init( plugin_basename( __FILE__ ) );
2016 bws_delete_plugin( plugin_basename( __FILE__ ) );
2017 }
2018 }
2019
2020 /* Adding function to output PDF document or pirnt page */
2021 register_activation_hook( __FILE__, 'pdfprnt_plugin_activate' );
2022 add_action( 'wp', 'pdfprnt_print', 20, 1 );
2023 add_action( 'wp_head', 'pdfprnt_auto_show_buttons_search_archive' );
2024 add_action( 'plugins_loaded', 'pdfprnt_plugins_loaded' );
2025 /* Initialization */
2026 add_action( 'init', 'pdfprnt_init' );
2027 add_action( 'admin_init', 'pdfprnt_admin_init' );
2028 /* Adding stylesheets */
2029 add_action( 'admin_enqueue_scripts', 'pdfprnt_admin_head' );
2030 add_action( 'wp_enqueue_scripts', 'pdfprnt_admin_head' );
2031 /* Adding 'BWS Plugins' admin menu */
2032 add_action( 'admin_menu', 'pdfprnt_add_admin_menu' );
2033 /* Add query vars */
2034 add_filter( 'query_vars', 'pdfprnt_print_vars_callback' );
2035
2036 add_shortcode( 'bws_pdfprint', 'pdfprnt_shortcode' );
2037 add_shortcode( 'bws_pdfprint_pagebreak', 'pdfprnt_shortcode_pagebreak' );
2038 /* custom filter for bws button in tinyMCE */
2039 add_filter( 'bws_shortcode_button_content', 'pdfprnt_shortcode_button_content' );
2040
2041 /* Additional links on the plugin page */
2042 add_filter( 'plugin_action_links', 'pdfprnt_action_links', 10, 2 );
2043 add_filter( 'plugin_row_meta', 'pdfprnt_links', 10, 2 );
2044 /* Adding buttons plugin to content */
2045 add_filter( 'the_content', 'pdfprnt_content' );
2046 /* Remove Print word from excerpt */
2047 add_filter( 'get_the_excerpt', 'pdfprnt_excerpt' );
2048 /* load additional fonts */
2049 add_action( 'wp_ajax_pdfprnt_load_fonts', 'pdfprnt_load_fonts' );
2050 /* load mPDF library */
2051 add_action( 'wp_ajax_pdfprnt_upgrade_library', 'pdfprnt_upgrade_library' );
2052 /* Adding banner */
2053 add_action( 'admin_notices', 'pdfprnt_plugin_banner' );
2054
2055 /* Register widget */
2056 add_action( 'widgets_init', 'pdfprnt_register_buttons_widget' );
2057
2058 add_action( 'bwsplgns_display_pdf_print_buttons', 'pdfprnt_display_plugin_buttons', 10, 2 );
2059