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

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