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