PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 2.4.1
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v2.4.1
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.1, at pdf-print.php

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