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

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