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