| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: PDF & Print by BestWebSoft |
| 4 |
Plugin URI: http://bestwebsoft.com/products/ |
| 5 |
Description: Plugin adds PDF creation and Print button on your site. |
| 6 |
Author: BestWebSoft |
| 7 |
Text Domain: pdf-print |
| 8 |
Domain Path: /languages |
| 9 |
Version: 1.8.8 |
| 10 |
Author URI: http://bestwebsoft.com/ |
| 11 |
License: GPLv2 or later |
| 12 |
*/ |
| 13 |
|
| 14 |
/* © Copyright 2016 BestWebSoft ( http://support.bestwebsoft.com ) |
| 15 |
|
| 16 |
This program is free software; you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License, version 2, as |
| 18 |
published by the Free Software Foundation. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
/* Add our own menu */ |
| 31 |
if ( ! function_exists( 'pdfprnt_add_pages' ) ) { |
| 32 |
function pdfprnt_add_pages() { |
| 33 |
bws_general_menu(); |
| 34 |
$settings = add_submenu_page( 'bws_plugins', __( 'PDF & Print Settings', 'pdf-print' ), 'PDF & Print', 'manage_options', 'pdf-print.php', 'pdfprnt_settings_page' ); |
| 35 |
add_action( "load-{$settings}", 'pdfprnt_add_tabs' ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Add help tab on settings page |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
if ( ! function_exists( 'pdfprnt_add_tabs' ) ) { |
| 44 |
function pdfprnt_add_tabs() { |
| 45 |
$args = array( |
| 46 |
'id' => 'pdfprnt', |
| 47 |
'section' => '200538669' |
| 48 |
); |
| 49 |
bws_help_tab( get_current_screen(), $args ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if ( ! function_exists( 'pdfprnt_plugins_loaded' ) ) { |
| 54 |
function pdfprnt_plugins_loaded() { |
| 55 |
/* Internationalization, first(!) */ |
| 56 |
load_plugin_textdomain( 'pdf-print', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/* Init plugin */ |
| 61 |
if ( ! function_exists ( 'pdfprnt_init' ) ) { |
| 62 |
function pdfprnt_init() { |
| 63 |
global $pdfprnt_plugin_info; |
| 64 |
$plugin_basename = plugin_basename( __FILE__ ); |
| 65 |
|
| 66 |
require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); |
| 67 |
bws_include_init( $plugin_basename ); |
| 68 |
|
| 69 |
if ( empty( $pdfprnt_plugin_info ) ) { |
| 70 |
if ( ! function_exists( 'get_plugin_data' ) ) { |
| 71 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 72 |
} |
| 73 |
$pdfprnt_plugin_info = get_plugin_data( __FILE__ ); |
| 74 |
} |
| 75 |
|
| 76 |
/* check WordPress version */ |
| 77 |
bws_wp_min_version_check( $plugin_basename, $pdfprnt_plugin_info, '3.8', "3.3" ); |
| 78 |
|
| 79 |
/* Get/Register and check settings for plugin */ |
| 80 |
if ( ! is_admin() || ( isset( $_GET['page'] ) && 'pdf-print.php' == $_GET['page'] ) ) |
| 81 |
pdfprnt_settings(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
if ( ! function_exists( 'pdfprnt_admin_init' ) ) { |
| 86 |
function pdfprnt_admin_init() { |
| 87 |
global $bws_plugin_info, $pdfprnt_plugin_info; |
| 88 |
|
| 89 |
if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) ) |
| 90 |
$bws_plugin_info = array( 'id' => '101', 'version' => $pdfprnt_plugin_info["Version"] ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/* Register settings for plugin */ |
| 95 |
if ( ! function_exists( 'pdfprnt_settings' ) ) { |
| 96 |
function pdfprnt_settings() { |
| 97 |
global $pdfprnt_options_array, $pdfprnt_plugin_info, $pdfprnt_options_defaults; |
| 98 |
|
| 99 |
if ( ! $pdfprnt_plugin_info ) { |
| 100 |
if ( ! function_exists( 'get_plugin_data' ) ) |
| 101 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 102 |
$pdfprnt_plugin_info = get_plugin_data( __FILE__ ); |
| 103 |
} |
| 104 |
|
| 105 |
/* Variable to verify performance number of once function. */ |
| 106 |
$pdfprnt_default_post_types = array(); |
| 107 |
/* Default post types of WordPress. */ |
| 108 |
foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1, '_builtin' => true ), 'names' ) as $value ) |
| 109 |
$pdfprnt_default_post_types[] = $value; |
| 110 |
|
| 111 |
$pdfprnt_options_defaults = array( |
| 112 |
'plugin_option_version' => $pdfprnt_plugin_info["Version"], |
| 113 |
'position' => 'top-right', |
| 114 |
'position_search_archive' => 'top-right', |
| 115 |
'position_custom' => 'right', |
| 116 |
'show_btn_print' => 1, |
| 117 |
'show_btn_pdf' => 1, |
| 118 |
'show_btn_print_search_archive' => 1, |
| 119 |
'show_btn_pdf_search_archive' => 1, |
| 120 |
'use_theme_stylesheet' => 0, |
| 121 |
'use_custom_styles' => 0, |
| 122 |
'custom_styles' => "", |
| 123 |
'tmpl_shorcode' => 1, |
| 124 |
'use_types_posts' => $pdfprnt_default_post_types, |
| 125 |
'show_print_window' => 0, |
| 126 |
'additional_fonts' => 0, |
| 127 |
'show_title' => 1, |
| 128 |
'show_featured_image' => 0, |
| 129 |
'first_install' => strtotime( "now" ), |
| 130 |
'suggest_feature_banner' => 1 |
| 131 |
); |
| 132 |
|
| 133 |
if ( ! get_option( 'pdfprnt_options_array' ) ) |
| 134 |
add_option( 'pdfprnt_options_array', $pdfprnt_options_defaults ); |
| 135 |
|
| 136 |
$pdfprnt_options_array = get_option( 'pdfprnt_options_array' ); |
| 137 |
|
| 138 |
if ( ! isset( $pdfprnt_options_array['plugin_option_version'] ) || $pdfprnt_options_array['plugin_option_version'] != $pdfprnt_plugin_info["Version"] ) { |
| 139 |
if ( in_array( $pdfprnt_options_array['position_search_archive'], array( 'pdfprnt-right', 'pdfprnt-left' ) ) ) |
| 140 |
$pdfprnt_options_array['position_search_archive'] = 'pdfprnt-left' == $pdfprnt_options_array['position_search_archive'] ? 'top-left' : 'top-right'; |
| 141 |
if ( in_array( $pdfprnt_options_array['position_custom'], array( 'pdfprnt-right', 'pdfprnt-left' ) ) ) |
| 142 |
$pdfprnt_options_array['position_custom'] = 'pdfprnt-left' == $pdfprnt_options_array['position_custom'] ? 'left' : 'right'; |
| 143 |
$pdfprnt_options_array = array_merge( $pdfprnt_options_defaults, $pdfprnt_options_array ); |
| 144 |
$pdfprnt_options_array['plugin_option_version'] = $pdfprnt_plugin_info["Version"]; |
| 145 |
$pdfprnt_options_array['hide_premium_options'] = array(); |
| 146 |
update_option( 'pdfprnt_options_array', $pdfprnt_options_array ); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Display <input type="radio"> on settings page |
| 153 |
**/ |
| 154 |
if ( ! function_exists( 'pdfprnt_display_radio' ) ) { |
| 155 |
function pdfprnt_display_radio( $name, $selected ) { |
| 156 |
$positions_values = array( |
| 157 |
'top-left' => __( 'Top Left', 'pdf-print' ), |
| 158 |
'top-right' => __( 'Top Right', 'pdf-print' ), |
| 159 |
'bottom-left' => __( 'Bottom Left', 'pdf-print' ), |
| 160 |
'bottom-right' => __( 'Bottom Right', 'pdf-print' ), |
| 161 |
'top-bottom-left' => __( 'Top & Bottom Left', 'pdf-print' ), |
| 162 |
'top-bottom-right' => __( 'Top & Bottom Right', 'pdf-print' ) |
| 163 |
); |
| 164 |
foreach ( $positions_values as $key => $value ) { ?> |
| 165 |
<label><input type="radio" name="<?php echo $name; ?>" value="<?php echo $key ?>"<?php echo $key == $selected ? ' checked="checked"' : ''; ?> /> <?php echo $value; ?></label><br/> |
| 166 |
<?php } |
| 167 |
} |
| 168 |
} |
| 169 |
/* Add admin page */ |
| 170 |
if ( ! function_exists ( 'pdfprnt_settings_page' ) ) { |
| 171 |
function pdfprnt_settings_page () { |
| 172 |
global $pdfprnt_options_array, $pdfprnt_plugin_info, $pdfprnt_options_defaults; |
| 173 |
$message = $error = ""; |
| 174 |
$plugin_basename = plugin_basename( __FILE__ ); |
| 175 |
if ( is_multisite() ) { |
| 176 |
switch_to_blog( 1 ); |
| 177 |
$upload_dir = wp_upload_dir(); |
| 178 |
restore_current_blog(); |
| 179 |
} else { |
| 180 |
$upload_dir = wp_upload_dir(); |
| 181 |
} |
| 182 |
$need_fonts_reload = false; |
| 183 |
$fonts_path = $upload_dir['basedir'] .'/pdf-print-fonts'; |
| 184 |
if ( ! function_exists( 'get_plugins' ) ) |
| 185 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 186 |
require_once( dirname( __FILE__ ) . '/includes/pro_banners.php' ); |
| 187 |
$all_plugins = get_plugins(); |
| 188 |
if ( isset( $_REQUEST['pdfprnt_form_submit'] ) && check_admin_referer( $plugin_basename, 'pdfprnt_nonce_name' ) ) { |
| 189 |
if ( isset( $_POST['bws_hide_premium_options'] ) ) { |
| 190 |
$hide_result = bws_hide_premium_options( $pdfprnt_options_array ); |
| 191 |
$pdfprnt_options_array = $hide_result['options']; |
| 192 |
} |
| 193 |
|
| 194 |
$pdfprnt_options_array['position'] = isset( $_REQUEST['pdfprnt_position'] ) ? $_REQUEST['pdfprnt_position'] : 'top-right'; |
| 195 |
$pdfprnt_options_array['position_search_archive'] = isset( $_REQUEST['pdfprnt_position_search_archive'] ) ? $_REQUEST['pdfprnt_position_search_archive'] : 'top-right'; |
| 196 |
$pdfprnt_options_array['position_custom'] = isset( $_REQUEST['pdfprnt_position_custom'] ) ? $_REQUEST['pdfprnt_position_custom'] : 'right'; |
| 197 |
$pdfprnt_options_array['use_theme_stylesheet'] = isset( $_REQUEST['pdfprnt_use_theme_stylesheet'] ) ? $_REQUEST['pdfprnt_use_theme_stylesheet'] : 0; |
| 198 |
$pdfprnt_options_array['show_btn_pdf'] = isset( $_REQUEST['pdfprnt_show_btn_pdf'] ) ? 1 : 0; |
| 199 |
$pdfprnt_options_array['show_btn_print'] = isset( $_REQUEST['pdfprnt_show_btn_print'] ) ? 1 : 0; |
| 200 |
$pdfprnt_options_array['show_btn_pdf_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_search_archive'] ) ? 1 : 0; |
| 201 |
$pdfprnt_options_array['show_btn_print_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_print_search_archive'] ) ? 1 : 0; |
| 202 |
$pdfprnt_options_array['tmpl_shorcode'] = isset( $_REQUEST['pdfprnt_tmpl_shorcode'] ) ? 1 : 0; |
| 203 |
$pdfprnt_options_array['show_print_window'] = isset( $_REQUEST['pdfprnt_show_print_window'] ) ? 1 : 0; |
| 204 |
$pdfprnt_options_array['use_types_posts'] = isset( $_REQUEST['pdfprnt_use_types_posts'] ) ? $_REQUEST['pdfprnt_use_types_posts'] : array(); |
| 205 |
$pdfprnt_options_array['use_custom_styles'] = isset( $_REQUEST['pdfprnt_use_custom_styles'] ) ? 1 : 0; |
| 206 |
$pdfprnt_options_array['show_title'] = isset( $_REQUEST['pdfprnt_show_title'] ) ? 1 : 0; |
| 207 |
$pdfprnt_options_array['show_featured_image'] = isset( $_REQUEST['pdfprnt_show_featured_image'] ) ? 1 : 0; |
| 208 |
if ( isset( $_REQUEST['pdfprnt_custom_styles'] ) ) { |
| 209 |
$custom_styles = stripslashes( esc_html( trim( $_REQUEST['pdfprnt_custom_styles'] ) ) ); |
| 210 |
if ( 10000 < strlen( $custom_styles ) ) |
| 211 |
$error .= __( 'You have entered too much text in the "edit styles" field.', 'pdf-print' ); |
| 212 |
else |
| 213 |
$pdfprnt_options_array['custom_styles'] = $custom_styles; |
| 214 |
} |
| 215 |
update_option( 'pdfprnt_options_array', $pdfprnt_options_array ); |
| 216 |
$message = __( 'Settings saved.', 'pdf-print' ); |
| 217 |
} |
| 218 |
if ( ! is_dir( $fonts_path ) && $pdfprnt_options_array['additional_fonts'] != 0 ) { /* if "pdf-print-fonts" folder was removed somehow */ |
| 219 |
$error = __( 'The folder "uploads/pdf-print-fonts" was removed', 'pdf-print' ); |
| 220 |
$need_fonts_reload = true; |
| 221 |
} elseif ( |
| 222 |
is_dir( $fonts_path ) && |
| 223 |
$pdfprnt_options_array['additional_fonts'] != count( scandir( $fonts_path ) ) && |
| 224 |
0 < $pdfprnt_options_array['additional_fonts'] |
| 225 |
) { /* if some fonts was removed somehow from "pdf-print-fonts" folder */ |
| 226 |
$error = __( 'Some fonts were removed from the folder "uploads/pdf-print-fonts"', 'pdf-print' ); |
| 227 |
$need_fonts_reload = true; |
| 228 |
} |
| 229 |
if ( $need_fonts_reload ) { |
| 230 |
$error .= '. ' . sprintf( |
| 231 |
__( 'You may need to reload fonts. For more info see %s', 'pdf-print' ), |
| 232 |
'<a href="http://bestwebsoft.com/products/pdf-print/faq" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>' |
| 233 |
); |
| 234 |
pdfprnt_update_option( -1, true ); |
| 235 |
} |
| 236 |
if ( isset( $_REQUEST['pdfprnt_load_fonts'] ) ) { |
| 237 |
/* load additional fonts if javascript is disabled */ |
| 238 |
$result = pdfprnt_load_fonts(); |
| 239 |
if ( isset( $result['error'] ) ) { |
| 240 |
$error .= ' ' . $result['error'] . '. ' . |
| 241 |
sprintf( |
| 242 |
__( 'You may need to reload fonts. For more info see %s', 'pdf-print' ), |
| 243 |
'<a href="http://bestwebsoft.com/products/pdf-print/faq" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>' |
| 244 |
); |
| 245 |
$need_fonts_reload = true; |
| 246 |
} |
| 247 |
if ( isset( $result['done'] ) ) |
| 248 |
$message .= ' ' . $result['done']; |
| 249 |
} |
| 250 |
if ( isset( $_REQUEST['bws_restore_confirm'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) { |
| 251 |
$pdfprnt_options_array = $pdfprnt_options_defaults; |
| 252 |
update_option( 'pdfprnt_options_array', $pdfprnt_options_array ); |
| 253 |
$message = __( 'All plugin settings were restored.', 'pdf-print' ); |
| 254 |
} |
| 255 |
|
| 256 |
/* GO PRO */ |
| 257 |
if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) { |
| 258 |
$go_pro_result = bws_go_pro_tab_check( $plugin_basename, 'pdfprnt_options_array' ); |
| 259 |
if ( ! empty( $go_pro_result['error'] ) ) |
| 260 |
$error = $go_pro_result['error']; |
| 261 |
elseif ( ! empty( $go_pro_result['message'] ) ) |
| 262 |
$message = $go_pro_result['message']; |
| 263 |
} ?> |
| 264 |
<div class="wrap"> |
| 265 |
<h1>PDF & Print<?php if ( isset( $_GET['action'] ) && 'templates' == $_GET['action'] ) { ?> <a href="admin.php?page=pdf-print.php&action=templates&pdfprnt_tab_action=new" class="add-new-h2 pdfprnt_add_new_button"><?php _e( 'Add New Template', 'pdf-print' ); ?></a><?php } ?></h1> |
| 266 |
<h2 class="nav-tab-wrapper"> |
| 267 |
<a class="nav-tab<?php if ( !isset( $_GET['action'] ) ) echo ' nav-tab-active'; ?>" href="admin.php?page=pdf-print.php"><?php _e( 'Settings', 'pdf-print' ); ?></a> |
| 268 |
<a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'extra' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=pdf-print.php&action=extra"><?php _e( 'Extra settings', 'pdf-print' ); ?></a> |
| 269 |
<a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'templates' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=pdf-print.php&action=templates"><?php _e( 'Templates', 'pdf-print' ); ?></a> |
| 270 |
<a class="nav-tab <?php if ( isset( $_GET['action'] ) && 'custom_code' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=pdf-print.php&action=custom_code"><?php _e( 'Custom code', 'pdf-print' ); ?></a> |
| 271 |
<a class="nav-tab bws_go_pro_tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=pdf-print.php&action=go_pro"><?php _e( 'Go PRO', 'pdf-print' ); ?></a> |
| 272 |
</h2> |
| 273 |
<div class="updated fade below-h2" <?php if ( empty( $message ) || "" != $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div> |
| 274 |
<div class="error below-h2" <?php if ( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div> |
| 275 |
<?php if ( ! empty( $hide_result['message'] ) ) { ?> |
| 276 |
<div class="updated fade below-h2"><p><strong><?php echo $hide_result['message']; ?></strong></p></div> |
| 277 |
<?php } |
| 278 |
$ttfontdata = plugin_dir_path( __FILE__ ) . 'mpdf/ttfontdata'; |
| 279 |
if ( ! is_writable( $ttfontdata ) ) { |
| 280 |
if ( ! @chmod( $ttfontdata, 0755 ) ) { ?> |
| 281 |
<div class="error below-h2"> |
| 282 |
<p> |
| 283 |
<strong> |
| 284 |
<?php _e( "Warning: Not enough rights for folder", 'pdf-print' ); ?> <i><?php echo $ttfontdata; ?></i>.<br /> |
| 285 |
<?php _e( 'Please check and change permissions for your plugins` folder ( for folders - 755, for files - 644 ). For more info see', 'pdf-print' ); ?> |
| 286 |
<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank"><?php _e( 'Changing File Permissions', 'pdf-print' ); ?></a> |
| 287 |
<?php _e( 'and', 'pdf-print' ); ?> |
| 288 |
<a href="http://bestwebsoft.com/products/pdf-print/faq" target="_blank"><?php _e( 'FAQ', 'pdf-print' ); ?></a>. |
| 289 |
</strong> |
| 290 |
</p> |
| 291 |
</div> |
| 292 |
<?php } |
| 293 |
} |
| 294 |
if ( ! isset( $_GET['action'] ) ) { |
| 295 |
if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) { |
| 296 |
bws_form_restore_default_confirm( $plugin_basename ); |
| 297 |
} else { |
| 298 |
bws_show_settings_notice(); ?> |
| 299 |
<form method="post" action="admin.php?page=pdf-print.php" id="pdfprnt_settings_form" class="bws_form"> |
| 300 |
<table class="form-table pdfprnt_settings_table"> |
| 301 |
<tr> |
| 302 |
<th scope="row"><?php _e( 'Types of posts that will be used in the plugin', 'pdf-print' ); ?></th> |
| 303 |
<td> |
| 304 |
<select name="pdfprnt_use_types_posts[]" multiple="multiple"> |
| 305 |
<?php foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1 ), 'objects' ) as $key => $value ) { |
| 306 |
if ( 'attachment' != $key ) { ?> |
| 307 |
<option value="<?php echo $key; ?>" <?php if ( in_array( $key, $pdfprnt_options_array['use_types_posts'] ) ) echo 'selected="selected"'; ?>><?php echo $value->label; ?></option> |
| 308 |
<?php } |
| 309 |
} ?> |
| 310 |
</select> |
| 311 |
</td> |
| 312 |
</tr> |
| 313 |
</table> |
| 314 |
<table class="form-table pdfprnt_settings_table pdfprnt_buttons"> |
| 315 |
<tr class="pdfprnt_table_head"> |
| 316 |
<th scope="row"></th> |
| 317 |
<th><?php _e( 'Posts and pages', 'pdf-print' ); ?></th> |
| 318 |
<th><?php _e( 'Search and archive pages', 'pdf-print' ); ?></th> |
| 319 |
</tr> |
| 320 |
<tr class="pdfprnt_pdf_buttton"> |
| 321 |
<th scope="row"><?php _e( 'Show PDF button', 'pdf-print' ); ?></th> |
| 322 |
<td> |
| 323 |
<input type="checkbox" name="pdfprnt_show_btn_pdf" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) echo 'checked="checked"'; ?> /> |
| 324 |
</td> |
| 325 |
<td> |
| 326 |
<input type="checkbox" name="pdfprnt_show_btn_pdf_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) echo 'checked="checked"'; ?> /> |
| 327 |
</td> |
| 328 |
</tr> |
| 329 |
<tr class="pdfprnt_print_buttton"> |
| 330 |
<th scope="row"><?php _e( 'Show Print button', 'pdf-print' ); ?></th> |
| 331 |
<td> |
| 332 |
<input type="checkbox" name="pdfprnt_show_btn_print" <?php if ( 1 == $pdfprnt_options_array['show_btn_print'] ) echo 'checked="checked"'; ?> /> |
| 333 |
</td> |
| 334 |
<td> |
| 335 |
<input type="checkbox" name="pdfprnt_show_btn_print_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) echo 'checked="checked"'; ?> /> |
| 336 |
</td> |
| 337 |
</tr> |
| 338 |
<tr class="pdfprnt_position_buttton"> |
| 339 |
<th scope="row"><?php _e( 'Position of buttons in the content', 'pdf-print' ); ?></th> |
| 340 |
<td> |
| 341 |
<fieldset><?php pdfprnt_display_radio( 'pdfprnt_position', $pdfprnt_options_array['position'] ); ?></fieldset> |
| 342 |
</td> |
| 343 |
<td> |
| 344 |
<fieldset><?php pdfprnt_display_radio( 'pdfprnt_position_search_archive', $pdfprnt_options_array['position_search_archive'] ); ?></fieldset> |
| 345 |
</td> |
| 346 |
</tr> |
| 347 |
</table> |
| 348 |
<div> |
| 349 |
<p> |
| 350 |
<?php _e( 'In order to use PDF and Print buttons in the custom post or page template, see', 'pdf-print' ); ?> <a href="http://bestwebsoft.com/products/pdf-print/faq/" target="_blank"><?php _e( 'FAQ', 'pdf-print' ); ?></a> |
| 351 |
</p> |
| 352 |
</div> |
| 353 |
<?php pdfprnt_pro_block( 'pdfprnt_image_block' ); ?> |
| 354 |
<table class="form-table pdfprnt_settings_table"> |
| 355 |
<tr id="pdfprnt_load_fonts_button"> |
| 356 |
<th scope="row"><?php _e( 'Load additional fonts', 'pdf-print' ); ?></th> |
| 357 |
<td style="position: relative;"> |
| 358 |
<?php if ( class_exists( 'ZipArchive' ) ) { |
| 359 |
$fonts_button_title = |
| 360 |
0 < $pdfprnt_options_array['additional_fonts'] || /* loading not called yet */ |
| 361 |
$need_fonts_reload /* loading occurred with errors or neccessary files lacks */ |
| 362 |
? |
| 363 |
__( 'Reload Fonts', 'pdf-print' ) |
| 364 |
: |
| 365 |
__( 'Load Fonts', 'pdf-print' ); ?> |
| 366 |
<input type="submit" class="button bws_no_bind_notice" value="<?php echo $fonts_button_title; ?>" name="pdfprnt_load_fonts" /> <span id="pdfprnt_font_loader" class="pdfprnt_loader"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" alt="loader" /></span><br /> |
| 367 |
<input type="hidden" name="pdfprnt_action" value="pdfprnt_load_fonts" /> |
| 368 |
<input type="hidden" name="pdfprnt_ajax_nonce" value="<?php echo wp_create_nonce( 'pdfprnt_ajax_nonce' ); ?>" /> |
| 369 |
<?php if ( 0 < $pdfprnt_options_array['additional_fonts'] ) { ?> |
| 370 |
<span><?php _e( 'Additional fonts were loaded successfully', 'pdf-print' ); ?>.</span> |
| 371 |
<?php } else { |
| 372 |
if ( -1 == $pdfprnt_options_array['additional_fonts'] ) { ?> |
| 373 |
<span><?php _e( 'If you have some problems with your internet connection, please, try to load additional fonts manually. For more info see', 'pdf-print' ); ?> <a href="http://bestwebsoft.com/products/pdf-print/faq" target="_blank"><?php _e( 'FAQ', 'pdf-print' ); ?></a>.</span><br /> |
| 374 |
<?php } ?> |
| 375 |
<span class="bws_info"><?php _e( 'You can load additional fonts, needed for the PDF creation. When creating the PDF-doc, this will allow automatic selection of fonts necessary for text, according to languages used in the content.', 'pdf-print' ); ?></span> |
| 376 |
<?php } |
| 377 |
} else { ?> |
| 378 |
<span style="color: red"><strong><?php _e( 'WARNING', 'pdf-print' ); ?>: </strong><?php _e( 'Class ZipArchive is not installed on your server. It is impossible to load additional fonts.', 'pdf-print' ); ?></span> |
| 379 |
<?php } ?> |
| 380 |
</td> |
| 381 |
</tr> |
| 382 |
<tr> |
| 383 |
<th scope="row"><?php _e( 'Use the theme stylesheet or plugin default style', 'pdf-print' ); ?></th> |
| 384 |
<td> |
| 385 |
<select name="pdfprnt_use_theme_stylesheet"> |
| 386 |
<option value="0" <?php if ( 0 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Default stylesheet', 'pdf-print' ); ?></option> |
| 387 |
<option value="1" <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Current theme stylesheet', 'pdf-print' ); ?></option> |
| 388 |
</select> |
| 389 |
</td> |
| 390 |
</tr> |
| 391 |
<tr> |
| 392 |
<th scope="row"><?php _e( 'Add custom styles', 'pdf-print' ); ?></th> |
| 393 |
<td> |
| 394 |
<input value="1" type="checkbox" name="pdfprnt_use_custom_styles" <?php if ( 1 == $pdfprnt_options_array['use_custom_styles'] ) echo 'checked="checked"'; ?> /> |
| 395 |
<div class="bws_help_box dashicons dashicons-editor-help"> |
| 396 |
<div class="bws_hidden_help_text" style="min-width: 200px;"> |
| 397 |
<p> |
| 398 |
<?php _e( 'Additional CSS-styles will be applied to your PDF/Print document', 'pdf-print' ); ?>.<br/> |
| 399 |
<?php _e( 'Learn more about', 'pdf-print' ); ?> <a href="http://www.w3schools.com/css/" target="_blank">CSS</a>. |
| 400 |
</p> |
| 401 |
</div> |
| 402 |
</div> |
| 403 |
</td> |
| 404 |
</tr> |
| 405 |
<tr class="pdfprnt_custom_styles"<?php if ( 1 != $pdfprnt_options_array['use_custom_styles'] ) echo ' style="display: none;"'; ?>> |
| 406 |
<th scope="row"></th> |
| 407 |
<td> |
| 408 |
<textarea id="pdfprnt_custom_styles" name="pdfprnt_custom_styles" maxlength="10000" cols="50" rows="5"><?php echo $pdfprnt_options_array['custom_styles']; ?></textarea><br /> |
| 409 |
<span class="bws_info"><?php _e( 'You can enter up to 10,000 characters', 'pdf-print' ); ?>.</span> |
| 410 |
|
| 411 |
</td> |
| 412 |
</tr> |
| 413 |
<tr> |
| 414 |
<th scope="row"><?php _e( 'Display additional elements', 'pdf-print' ); ?></th> |
| 415 |
<td><fieldset> |
| 416 |
<label><input type="checkbox" name="pdfprnt_show_title" <?php if ( 1 == $pdfprnt_options_array['show_title'] ) echo 'checked="checked"'; ?> /> <?php _e( 'Title', 'pdf-print' ); ?></label><br/> |
| 417 |
<label><input type="checkbox" name="pdfprnt_show_featured_image" <?php if ( 1 == $pdfprnt_options_array['show_featured_image'] ) echo 'checked="checked"'; ?> /> <?php _e( 'Featured image', 'pdf-print' ); ?></label> |
| 418 |
</fieldset></td> |
| 419 |
</tr> |
| 420 |
<tr> |
| 421 |
<th scope="row"> |
| 422 |
<?php _e( 'Settings for shortcodes', 'pdf-print' ); ?> |
| 423 |
</th> |
| 424 |
<td> |
| 425 |
<label><input type="checkbox" name="pdfprnt_tmpl_shorcode" <?php if ( 1 == $pdfprnt_options_array['tmpl_shorcode'] ) echo 'checked="checked"'; ?> /> <span><?php _e( 'Do!', 'pdf-print' ); ?></span></label> |
| 426 |
</td> |
| 427 |
</tr> |
| 428 |
<tr> |
| 429 |
<th scope="row"><?php _e( 'Show the print window', 'pdf-print' ); ?></th> |
| 430 |
<td> |
| 431 |
<input type="checkbox" name="pdfprnt_show_print_window" <?php if ( 1 == $pdfprnt_options_array['show_print_window'] ) echo 'checked="checked"'; ?> /> |
| 432 |
</td> |
| 433 |
</tr> |
| 434 |
</table> |
| 435 |
<?php pdfprnt_pro_block( 'pdfprnt_woocommerce_block' ); ?> |
| 436 |
<input type="hidden" name="pdfprnt_form_submit" value="1" /> |
| 437 |
<p class="submit"> |
| 438 |
<input type="submit" id="bws-submit-button" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" /> |
| 439 |
</p> |
| 440 |
<?php wp_nonce_field( $plugin_basename, 'pdfprnt_nonce_name' ); ?> |
| 441 |
</form> |
| 442 |
<?php bws_form_restore_default_settings( $plugin_basename ); |
| 443 |
} |
| 444 |
} else { |
| 445 |
switch ( $_GET['action'] ) { |
| 446 |
case 'extra': |
| 447 |
case 'templates': |
| 448 |
$new = isset( $_GET['pdfprnt_tab_action'] ) && 'new' == $_GET['pdfprnt_tab_action'] ? '_new' : ''; |
| 449 |
pdfprnt_pro_block( "pdfprnt_{$_GET['action']}{$new}_block", false ); |
| 450 |
break; |
| 451 |
case 'custom_code': |
| 452 |
bws_custom_code_tab(); |
| 453 |
case 'go_pro': |
| 454 |
$show = bws_hide_premium_options_check( $pdfprnt_options_array ) ? true : false; |
| 455 |
bws_go_pro_tab_show( |
| 456 |
$show, |
| 457 |
$pdfprnt_plugin_info, |
| 458 |
$plugin_basename, |
| 459 |
'pdf-print.php', |
| 460 |
'pdf-print-pro.php', |
| 461 |
'pdf-print-pro/pdf-print-pro.php', |
| 462 |
'pdf-print', |
| 463 |
'd9da7c9c2046bed8dfa38d005d4bffdb', |
| 464 |
'101', |
| 465 |
isset( $go_pro_result['pro_plugin_is_activated'] ) |
| 466 |
); |
| 467 |
break; |
| 468 |
default: |
| 469 |
break; |
| 470 |
} |
| 471 |
} |
| 472 |
bws_plugin_reviews_block( $pdfprnt_plugin_info['Name'], 'pdf-print' ); ?> |
| 473 |
</div> |
| 474 |
<?php } |
| 475 |
} |
| 476 |
|
| 477 |
/* Positioning buttons in the page */ |
| 478 |
if ( ! function_exists( 'pdfprnt_content' ) ) { |
| 479 |
function pdfprnt_content( $content ) { |
| 480 |
global $pdfprnt_options_array, $post; |
| 481 |
|
| 482 |
if ( is_admin() || is_feed() || is_search() || is_archive() || is_category() || is_tax() || is_tag() || is_author() || ! in_array( $post->post_type, $pdfprnt_options_array['use_types_posts'] ) ) |
| 483 |
return $content; |
| 484 |
|
| 485 |
if ( 1 == $pdfprnt_options_array['show_btn_pdf'] || 1 == $pdfprnt_options_array['show_btn_print'] ) { |
| 486 |
$str = '<div class="pdfprnt-' . $pdfprnt_options_array['position'] . '">'; |
| 487 |
if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) { |
| 488 |
if ( ! is_front_page () ) |
| 489 |
$permalink = add_query_arg( 'print' , 'pdf' , get_permalink( $post->ID ) ); |
| 490 |
else |
| 491 |
$permalink = add_query_arg( 'print' , 'pdf' , get_permalink() . '?page_id=' . $post->ID ); |
| 492 |
$str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="View PDF" /></a>'; |
| 493 |
} |
| 494 |
if ( 1 == $pdfprnt_options_array['show_btn_print'] ) { |
| 495 |
if ( ! is_front_page () ) |
| 496 |
$permalink = add_query_arg( 'print' , 'print' , get_permalink( $post->ID ) ); |
| 497 |
else |
| 498 |
$permalink = add_query_arg( 'print' , 'print' , get_permalink() . '?page_id=' . $post->ID ); |
| 499 |
$str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>'; |
| 500 |
} |
| 501 |
$str .= '</div>'; |
| 502 |
|
| 503 |
if ( 'top-left' == $pdfprnt_options_array['position'] || 'top-right' == $pdfprnt_options_array['position'] ) |
| 504 |
$content = $str . $content; |
| 505 |
elseif ( 'bottom-left' == $pdfprnt_options_array['position'] || 'bottom-right' == $pdfprnt_options_array['position'] ) |
| 506 |
$content = $content . $str; |
| 507 |
else |
| 508 |
$content = $str . $content . $str; |
| 509 |
} |
| 510 |
return $content; |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
/* Output buttons for search or archive pages */ |
| 515 |
if ( ! function_exists( 'pdfprnt_show_buttons_search_archive' ) ) { |
| 516 |
function pdfprnt_show_buttons_search_archive( $content ) { |
| 517 |
global $wp_query; |
| 518 |
/* make sure that we display pdf/print buttons only with main loop */ |
| 519 |
if ( is_main_query() && $content === $wp_query ) { |
| 520 |
global $pdfprnt_options_array, $wp, $posts, $pdfprnt_show_archive_start, $pdfprnt_show_archive_end; |
| 521 |
$loop_position = current_filter(); |
| 522 |
if ( ! ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] || 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) ) |
| 523 |
return; |
| 524 |
/* Check for existence the type of posts. */ |
| 525 |
$is_return = true; |
| 526 |
foreach ( $posts as $post ) { |
| 527 |
if ( in_array( $post->post_type, $pdfprnt_options_array['use_types_posts'] ) ) { |
| 528 |
$is_return = false; |
| 529 |
break; |
| 530 |
} |
| 531 |
} |
| 532 |
if ( $is_return ) |
| 533 |
return; |
| 534 |
|
| 535 |
if ( ( 'loop_start' == $loop_position && $pdfprnt_show_archive_start == 1 ) || ( 'loop_end' == $loop_position && $pdfprnt_show_archive_end == 1 ) ) |
| 536 |
return; |
| 537 |
|
| 538 |
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
| 539 |
|
| 540 |
$str = '<div class="pdfprnt-' . $pdfprnt_options_array['position_search_archive'] . '">'; |
| 541 |
if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) { |
| 542 |
$permalink = add_query_arg( 'print' , 'pdf-search' , $current_url ); |
| 543 |
$str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>'; |
| 544 |
} |
| 545 |
if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) { |
| 546 |
$permalink = add_query_arg( 'print' , 'print-search' , $current_url ); |
| 547 |
$str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>'; |
| 548 |
} |
| 549 |
$str .= '</div>'; |
| 550 |
echo $str; |
| 551 |
if ( 'loop_start' == $loop_position ) |
| 552 |
$pdfprnt_show_archive_start++; |
| 553 |
elseif ( 'loop_end' == $loop_position ) |
| 554 |
$pdfprnt_show_archive_end++; |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
/** |
| 560 |
* Add buttons before or after the loop |
| 561 |
*/ |
| 562 |
if ( ! function_exists( 'pdfprnt_auto_show_buttons_search_archive' ) ) { |
| 563 |
function pdfprnt_auto_show_buttons_search_archive() { |
| 564 |
if ( is_search() || is_archive() || is_category() || is_tax() || is_tag() || is_author() ) { |
| 565 |
global $pdfprnt_options_array, $pdfprnt_show_archive_start, $pdfprnt_show_archive_end; |
| 566 |
$pdfprnt_show_archive_start = $pdfprnt_show_archive_end = 0; |
| 567 |
if ( in_array( $pdfprnt_options_array['position_search_archive'], array( 'top-left', 'top-right' ) ) ) { |
| 568 |
add_action( 'loop_start', 'pdfprnt_show_buttons_search_archive' ); |
| 569 |
} elseif ( in_array( $pdfprnt_options_array['position_search_archive'], array( 'bottom-left', 'bottom-right' ) ) ) { |
| 570 |
add_action( 'loop_end', 'pdfprnt_show_buttons_search_archive' ); |
| 571 |
} else { |
| 572 |
add_action( 'loop_start', 'pdfprnt_show_buttons_search_archive' ); |
| 573 |
add_action( 'loop_end', 'pdfprnt_show_buttons_search_archive' ); |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
/** |
| 580 |
* Output buttons of page for BWS Portfolio plugin |
| 581 |
* @deprecated since 1.8.4 |
| 582 |
*/ |
| 583 |
if( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio' ) ) { |
| 584 |
function pdfprnt_show_buttons_for_bws_portfolio() { |
| 585 |
return pdfprnt_show_buttons_for_custom_post_type(); |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
/** |
| 590 |
* Output buttons of post for BWS Portfolio plugin |
| 591 |
* @deprecated since 1.8.4 |
| 592 |
*/ |
| 593 |
if ( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio_post' ) ) { |
| 594 |
function pdfprnt_show_buttons_for_bws_portfolio_post() { |
| 595 |
return pdfprnt_show_buttons_for_custom_post_type(); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
/** |
| 601 |
* Display plugin buttons via action call |
| 602 |
* @param string $where where to display |
| 603 |
* @param mixed $user_query WP_Query parameters |
| 604 |
*/ |
| 605 |
if ( ! function_exists( 'pdfprnt_display_plugin_butttons' ) ) { |
| 606 |
function pdfprnt_display_plugin_butttons( $where = 'top', $user_query = '' ) { |
| 607 |
global $pdfprnt_options_array; |
| 608 |
if ( preg_match( "|" . $where . "|", $pdfprnt_options_array['position'] ) || empty( $where ) ) |
| 609 |
echo pdfprnt_show_buttons_for_custom_post_type( $user_query ); |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
/* Output buttons of page for custom post type */ |
| 614 |
if ( ! function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) { |
| 615 |
function pdfprnt_show_buttons_for_custom_post_type( $user_query = '' ) { |
| 616 |
global $pdfprnt_options_array, $post, $wp, $posts; |
| 617 |
if ( |
| 618 |
/* not display anything if displaying buttons for post and pages is disabled */ |
| 619 |
( ! ( 1 == $pdfprnt_options_array['show_btn_pdf'] || 1 == $pdfprnt_options_array['show_btn_print'] ) ) || |
| 620 |
/* not display anything if we have wrong $user_query */ |
| 621 |
( ! ( is_array( $user_query ) || is_string( $user_query ) ) ) |
| 622 |
) |
| 623 |
return; |
| 624 |
|
| 625 |
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
| 626 |
$is_return = true; |
| 627 |
|
| 628 |
if ( empty( $user_query ) ) { /* set necessary values of parameters for pdf/print buttons */ |
| 629 |
$nothing_else = false; |
| 630 |
if ( is_search() || is_archive() || is_category() || is_tax() || is_tag() || is_author() ) { /* search, cattegories, archives */ |
| 631 |
foreach ( $posts as $value ) { |
| 632 |
if ( in_array( $value->post_type, $pdfprnt_options_array['use_types_posts'] ) ) { |
| 633 |
$is_return = false; |
| 634 |
break; |
| 635 |
} |
| 636 |
} |
| 637 |
if ( $is_return ) |
| 638 |
return; |
| 639 |
$pdf_query_parameter = 'pdf-search'; |
| 640 |
$print_query_parameter = 'print-search'; |
| 641 |
} elseif ( is_page() ) { /* pages */ |
| 642 |
if ( in_array( 'page', $pdfprnt_options_array['use_types_posts'] ) ) { |
| 643 |
$nothing_else = true; |
| 644 |
} else { |
| 645 |
return; |
| 646 |
} |
| 647 |
} elseif ( is_single() ) { /* posts */ |
| 648 |
$post_type = get_post_type( $post->ID ); |
| 649 |
if ( in_array( $post_type, $pdfprnt_options_array['use_types_posts'] ) ) { |
| 650 |
$nothing_else = true; |
| 651 |
} else { |
| 652 |
return; |
| 653 |
} |
| 654 |
} else { |
| 655 |
$nothing_else = true; |
| 656 |
} |
| 657 |
if ( $nothing_else ) { |
| 658 |
$pdf_query_parameter = 'pdf'; |
| 659 |
$print_query_parameter = 'print'; |
| 660 |
} |
| 661 |
} else { |
| 662 |
$custom_query = new WP_Query( $user_query ); |
| 663 |
$current_url = add_query_arg( $custom_query->query, '', $current_url ); |
| 664 |
/* Check for existence the type of posts. */ |
| 665 |
if ( ! empty( $custom_query->posts) ) { |
| 666 |
foreach ( $custom_query->posts as $post ) { |
| 667 |
if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) { |
| 668 |
$is_return = false; |
| 669 |
break; |
| 670 |
} |
| 671 |
} |
| 672 |
} |
| 673 |
if ( $is_return ) |
| 674 |
return; |
| 675 |
$pdf_query_parameter = 'pdf-custom'; |
| 676 |
$print_query_parameter = 'print-custom'; |
| 677 |
} |
| 678 |
|
| 679 |
$str = '<div class="pdfprnt-' . $pdfprnt_options_array['position'] . '">'; |
| 680 |
if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) { |
| 681 |
$permalink = add_query_arg( 'print' , $pdf_query_parameter , $current_url ); |
| 682 |
$str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>'; |
| 683 |
} |
| 684 |
if ( 1 == $pdfprnt_options_array['show_btn_print'] ) { |
| 685 |
$permalink = add_query_arg( 'print' , $print_query_parameter , $current_url ); |
| 686 |
$str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>'; |
| 687 |
} |
| 688 |
$str .= '</div>'; |
| 689 |
return $str; |
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
/* Add links */ |
| 694 |
if ( ! function_exists( 'pdfprnt_action_links' ) ) { |
| 695 |
function pdfprnt_action_links( $links, $file ) { |
| 696 |
if ( ! is_network_admin() ) { |
| 697 |
$base = plugin_basename( __FILE__ ); |
| 698 |
if ( $file == $base ) { |
| 699 |
$settings_link = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>'; |
| 700 |
array_unshift( $links, $settings_link ); |
| 701 |
} |
| 702 |
} |
| 703 |
return $links; |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
/* Add links */ |
| 708 |
if ( ! function_exists( 'pdfprnt_links' ) ) { |
| 709 |
function pdfprnt_links( $links, $file ) { |
| 710 |
$base = plugin_basename( __FILE__ ); |
| 711 |
if ( $file == $base ) { |
| 712 |
if ( ! is_network_admin() ) |
| 713 |
$links[] = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>'; |
| 714 |
$links[] = '<a href="http://wordpress.org/plugins/pdf-print/faq/" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>'; |
| 715 |
$links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'pdf-print' ) . '</a>'; |
| 716 |
} |
| 717 |
return $links; |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
/* Add stylesheets */ |
| 722 |
if ( ! function_exists ( 'pdfprnt_admin_head' ) ) { |
| 723 |
function pdfprnt_admin_head() { |
| 724 |
$is_plugin_options = isset( $_GET['page'] ) && $_GET['page'] == "pdf-print.php"; |
| 725 |
|
| 726 |
if ( ! is_admin() || $is_plugin_options ) |
| 727 |
wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style.css', __FILE__ ) ); |
| 728 |
|
| 729 |
if ( $is_plugin_options ) { |
| 730 |
bws_plugins_include_codemirror(); |
| 731 |
wp_enqueue_script( 'pdfprnt_script', plugins_url( 'js/script.js', __FILE__ ) ); |
| 732 |
wp_localize_script( 'pdfprnt_script', 'pdfprnt_var', array( |
| 733 |
'loading_fonts' => __( 'Loading of fonts. It might take a several minutes', 'pdf-print' ), |
| 734 |
'ajax_nonce' => wp_create_nonce( 'pdfprnt_ajax_nonce' ), |
| 735 |
'need_reload' => '. ' . sprintf( |
| 736 |
__( 'You may need to reload fonts. For more info see %s', 'pdf-print' ), |
| 737 |
'<a href="http://bestwebsoft.com/products/pdf-print/faq" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>' |
| 738 |
) |
| 739 |
) |
| 740 |
); |
| 741 |
|
| 742 |
|
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
/* Remove inline 'font-family' and 'font' styles from content */ |
| 747 |
if ( ! function_exists( 'pdfprnt_preg_replace' ) ) { |
| 748 |
function pdfprnt_preg_replace( $patterns, $content ) { |
| 749 |
foreach( $patterns as $pattern ) { |
| 750 |
$content = preg_replace( "/" . $pattern . "(.*?);/", "", $content ); |
| 751 |
preg_match_all( "~style=(\"\'?)~", $content, $quotes );/* get array with quotes */ |
| 752 |
if ( isset( $quotes[1] ) && ! empty( $quotes[1] ) ) { |
| 753 |
foreach ( $quotes[1] as $quote ) { |
| 754 |
preg_match_all( "~style=" . $quote . "(.*?)" . $quote . "~", $content, $styles ); |
| 755 |
if ( ! empty( $styles[1] ) ) { |
| 756 |
foreach ( $styles[1] as $style ) { |
| 757 |
if ( preg_match( "/" . $pattern . "/", $style ) ) |
| 758 |
$content = preg_replace( "/" . $style . "/", "", $content ); |
| 759 |
} |
| 760 |
|
| 761 |
} |
| 762 |
} |
| 763 |
} |
| 764 |
} |
| 765 |
return $content; |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
/* Generate templates for pdf file or print */ |
| 770 |
if ( ! function_exists( 'pdfprnt_generate_template' ) ) { |
| 771 |
function pdfprnt_generate_template( $content, $isprint = false ) { |
| 772 |
global $pdfprnt_options_array; |
| 773 |
$html = |
| 774 |
'<html> |
| 775 |
<head>'; |
| 776 |
if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) { |
| 777 |
/* remove 'font-family' and 'font' styles from theme css-file if additional fonts not loaded */ |
| 778 |
if ( 0 == $pdfprnt_options_array['additional_fonts'] ) { |
| 779 |
$css = file_get_contents( get_bloginfo( 'stylesheet_url' ) ); |
| 780 |
if ( ( ! empty( $css ) ) ) |
| 781 |
$html .= '<style type="text/css">' . preg_replace( "/(font:(.*?);)|(font-family(.*?);)/", "", $css ) . '</style>'; |
| 782 |
} else { |
| 783 |
$html .= '<link type="text/css" rel="stylesheet" href="' . get_bloginfo( 'stylesheet_url' ) . '" media="all" />'; |
| 784 |
} |
| 785 |
} else { |
| 786 |
$html .= '<link type="text/css" rel="stylesheet" href="' . plugins_url( 'css/default.css', __FILE__ ) . '" media="all" />'; |
| 787 |
} |
| 788 |
$html .= pdfprnt_additional_styles( $isprint ); |
| 789 |
if ( 1 == $pdfprnt_options_array['use_custom_styles'] && ! empty( $pdfprnt_options_array['custom_styles'] ) ) |
| 790 |
$html .= '<style type="text/css">' . $pdfprnt_options_array['custom_styles'] . '</style>'; |
| 791 |
if ( $isprint && 1 == $pdfprnt_options_array['show_print_window'] ) |
| 792 |
$html .= '<script>window.onload = function(){ window.print(); };</script>'; |
| 793 |
$html .= |
| 794 |
'</head> |
| 795 |
<body' . ( $isprint ? ' class="pdfprnt_print"' : '' ) . '>'; |
| 796 |
/* Remove inline 'font-family' and 'font' styles from content */ |
| 797 |
if ( 0 == $pdfprnt_options_array['additional_fonts'] ) |
| 798 |
$content = pdfprnt_preg_replace( array( "font-family", "font:" ), $content ); |
| 799 |
$html .= $content . |
| 800 |
'</body> |
| 801 |
</html>'; |
| 802 |
return $html; |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
if ( ! function_exists( 'pdfprnt_additional_styles' ) ) { |
| 807 |
function pdfprnt_additional_styles( $isprint ) { |
| 808 |
$styles = apply_filters( 'bwsplgns_add_pdf_print_styles', array() ); |
| 809 |
$html = ''; |
| 810 |
if ( ! empty( $styles ) && is_array( $styles ) ) { |
| 811 |
$url = get_bloginfo( 'url' ); |
| 812 |
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 813 |
$path = get_home_path(); |
| 814 |
foreach ( $styles as $style ) { |
| 815 |
if ( ! empty( $style[0] ) && file_exists( $path . $style[0] ) ) { |
| 816 |
/* if "get print" */ |
| 817 |
if ( $isprint ) { |
| 818 |
if( ( isset( $style[1] ) && 'print' == $style[1] ) || ! isset( $style[1] ) ) |
| 819 |
$html .= '<link type="text/css" rel="stylesheet" href="' . $url . '/' . $style[0] . '" media="all" />'; |
| 820 |
/* if "get pdf" */ |
| 821 |
} else { |
| 822 |
if ( ( isset( $style[1] ) && 'pdf' == $style[1] ) || ! isset( $style[1] ) ) |
| 823 |
$html .= '<link type="text/css" rel="stylesheet" href="' . $url . '/' . $style[0] . '" media="all" />'; |
| 824 |
} |
| 825 |
} |
| 826 |
} |
| 827 |
} |
| 828 |
return $html; |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
/* Output print page or pdf document and include plugin script */ |
| 833 |
if ( ! function_exists( 'pdfprnt_print' ) ) { |
| 834 |
function pdfprnt_print( $query ) { |
| 835 |
global $pdfprnt_options_array, $posts, $post; |
| 836 |
|
| 837 |
if ( ! $print = get_query_var( 'print' ) ) |
| 838 |
return; |
| 839 |
|
| 840 |
remove_all_filters( 'the_content' ); |
| 841 |
add_filter( 'the_content', 'capital_P_dangit', 11 ); |
| 842 |
add_filter( 'the_content', 'wptexturize' ); |
| 843 |
add_filter( 'the_content', 'convert_smilies' ); |
| 844 |
add_filter( 'the_content', 'convert_chars' ); |
| 845 |
add_filter( 'the_content', 'wpautop' ); |
| 846 |
if ( ! 0 == $pdfprnt_options_array['tmpl_shorcode'] ) { |
| 847 |
add_filter( 'the_content', 'do_shortcode' ); |
| 848 |
$pattern = false; |
| 849 |
} else { |
| 850 |
$pattern = get_shortcode_regex(); |
| 851 |
} |
| 852 |
|
| 853 |
$doc_type = explode( '-', $print ); |
| 854 |
|
| 855 |
if ( ! is_array( $doc_type ) ) |
| 856 |
return; |
| 857 |
|
| 858 |
/* for seach or archives */ |
| 859 |
if ( isset( $doc_type[1] ) ) { |
| 860 |
switch ( $doc_type[1] ) { |
| 861 |
case 'custom': |
| 862 |
$url_data = parse_url( $_SERVER['REQUEST_URI'] ); |
| 863 |
parse_str( $url_data['query'], $args ); |
| 864 |
unset( $args['print'] ); |
| 865 |
if ( ! empty( $args ) ) |
| 866 |
$posts = query_posts( $args ); |
| 867 |
break; |
| 868 |
case 'search': |
| 869 |
default: |
| 870 |
break; |
| 871 |
} |
| 872 |
/* for single posts or pages */ |
| 873 |
} else { |
| 874 |
$posts = array( $post ); |
| 875 |
} |
| 876 |
|
| 877 |
switch( $doc_type[0] ) { |
| 878 |
case 'pdf': |
| 879 |
|
| 880 |
/* set path to directory with fonts */ |
| 881 |
if ( ! ( 0 == $pdfprnt_options_array['additional_fonts'] && defined( "_MPDF_SYSTEM_TTFONTS" ) ) ) { |
| 882 |
if ( is_multisite() ) { |
| 883 |
switch_to_blog( 1 ); |
| 884 |
$upload_dir = wp_upload_dir(); |
| 885 |
restore_current_blog(); |
| 886 |
} else { |
| 887 |
$upload_dir = wp_upload_dir(); |
| 888 |
} |
| 889 |
define( '_MPDF_SYSTEM_TTFONTS', $upload_dir['basedir'] .'/pdf-print-fonts/' ); |
| 890 |
} |
| 891 |
|
| 892 |
/* prepare data */ |
| 893 |
$titles = $authors = array(); |
| 894 |
$default_font = 0 == $pdfprnt_options_array['additional_fonts'] ? 'dejavusansmono' : ''; |
| 895 |
$last = count( $posts ); |
| 896 |
$i = 1; |
| 897 |
$html = '<div id="content">'; |
| 898 |
foreach ( $posts as $p ) { |
| 899 |
|
| 900 |
if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) ) |
| 901 |
continue; |
| 902 |
|
| 903 |
$titles[] = $p->post_title; |
| 904 |
$user_info = get_userdata( $p->post_author ); |
| 905 |
$authors[] = $user_info->display_name; |
| 906 |
$title = 1 == $pdfprnt_options_array['show_title'] ? '<div class="entry-header"><h1 class="entry-title"><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>' : ''; |
| 907 |
$image = 1 == $pdfprnt_options_array['show_featured_image'] && has_post_thumbnail( $p->ID ) ? '<div class="entry-thumbnail">' . get_the_post_thumbnail( $p->ID ) . '</div>' : ''; |
| 908 |
/* replacing shortcodes to an empty string which were added to the content */ |
| 909 |
if ( $pattern && preg_match_all( '/'. $pattern .'/s', $p->post_content, $matches ) ) { |
| 910 |
foreach ( array_unique( $matches[0] ) as $value ) |
| 911 |
$p->post_content = str_replace( $value, "", $p->post_content ); |
| 912 |
} |
| 913 |
$html .= |
| 914 |
'<div class="post">' . |
| 915 |
$image . |
| 916 |
$title . |
| 917 |
'<div class="entry-content">' . apply_filters( 'bwsplgns_get_pdf_print_content', apply_filters( 'the_content', $p->post_content ), $p ) . '</div> |
| 918 |
</div>'; |
| 919 |
if ( $i != $last ) { |
| 920 |
$html .= '<br/><hr/><br/>'; |
| 921 |
$i ++; |
| 922 |
} |
| 923 |
} |
| 924 |
$html .= '</div>'; |
| 925 |
$titles = array_unique( $titles ); |
| 926 |
$authors = array_unique( $authors ); |
| 927 |
|
| 928 |
/* generate PDF-document */ |
| 929 |
include ( 'mpdf/mpdf.php' ); |
| 930 |
$mpdf = new mPDF( '+aCJK', 'A4', 0, $default_font ); |
| 931 |
$mpdf->allow_charset_conversion = true; |
| 932 |
$mpdf->charset_in = get_bloginfo( 'charset' ); |
| 933 |
if ( 0 != $pdfprnt_options_array['additional_fonts'] ) { |
| 934 |
$mpdf->autoScriptToLang = true; |
| 935 |
$mpdf->autoLangToFont = true; |
| 936 |
$mpdf->baseScript = 1; |
| 937 |
$mpdf->autoVietnamese = true; |
| 938 |
$mpdf->autoArabic = true; |
| 939 |
} |
| 940 |
if ( is_rtl() ) |
| 941 |
$mpdf->SetDirectionality( 'rtl' ); |
| 942 |
$mpdf->SetTitle( implode( ',', $titles ) ); |
| 943 |
$mpdf->SetAuthor( implode( ',', $authors ) ); |
| 944 |
$mpdf->SetSubject( get_bloginfo( 'blogdescription' ) ); |
| 945 |
$mpdf->WriteHTML( pdfprnt_generate_template( $html ) ); |
| 946 |
$mpdf->Output(); |
| 947 |
break; |
| 948 |
case 'print': |
| 949 |
|
| 950 |
$last = count( $posts ); |
| 951 |
$i = 1; |
| 952 |
$html = '<div id="content">'; |
| 953 |
foreach ( $posts as $p ) { |
| 954 |
|
| 955 |
if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) ) |
| 956 |
continue; |
| 957 |
|
| 958 |
$title = 1 == $pdfprnt_options_array['show_title'] ? '<div class="entry-header"><h1 class="entry-title">' . $p->post_title . '</h1></div><br/>' : ''; |
| 959 |
$image = 1 == $pdfprnt_options_array['show_featured_image'] && has_post_thumbnail( $p->ID ) ? '<div class="entry-thumbnail">' . get_the_post_thumbnail( $p->ID ) . '</div>' : ''; |
| 960 |
/* replacing shortcodes to an empty string which were added to the content */ |
| 961 |
if ( $pattern && preg_match_all( '/'. $pattern .'/s', $p->post_content, $matches ) ) { |
| 962 |
foreach ( array_unique( $matches[0] ) as $value ) |
| 963 |
$p->post_content = str_replace( $value, "", $p->post_content ); |
| 964 |
} |
| 965 |
$html .= |
| 966 |
'<div class="post">' . |
| 967 |
$image . |
| 968 |
$title . |
| 969 |
'<div class="entry-content">' . apply_filters( 'bwsplgns_get_pdf_print_content', apply_filters( 'the_content', $p->post_content ), $p ) . '</div> |
| 970 |
</div>'; |
| 971 |
if ( $i != $last ) { |
| 972 |
$html .= '<br/><hr/><br/>'; |
| 973 |
$i ++; |
| 974 |
} |
| 975 |
} |
| 976 |
$html .= '</div>'; |
| 977 |
echo pdfprnt_generate_template( $html, true ); |
| 978 |
die(); |
| 979 |
default: |
| 980 |
break; |
| 981 |
} |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
/* Add query vars */ |
| 986 |
if ( ! function_exists( 'print_vars_callback' ) ) { |
| 987 |
function print_vars_callback( $query_vars ) { |
| 988 |
$query_vars[] = 'print'; |
| 989 |
return $query_vars; |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
/** |
| 994 |
* Class Pdfprnt_ZipArchive for extracting |
| 995 |
* necessary folder from zip-archive |
| 996 |
*/ |
| 997 |
if ( class_exists( 'ZipArchive' ) && ! class_exists( 'Pdfprnt_ZipArchive' ) ) { |
| 998 |
class Pdfprnt_ZipArchive extends ZipArchive { |
| 999 |
/** |
| 1000 |
* constructor of class |
| 1001 |
*/ |
| 1002 |
public function extractSubdirTo( $destination, $subdir ) { |
| 1003 |
$errors = array(); |
| 1004 |
$charset = get_bloginfo( 'charset' ); |
| 1005 |
// Prepare dirs |
| 1006 |
$destination = str_replace( array("/", "\\"), DIRECTORY_SEPARATOR, $destination ); |
| 1007 |
$subdir = str_replace( array("/", "\\"), "/", $subdir); |
| 1008 |
|
| 1009 |
if ( substr( $destination, mb_strlen( DIRECTORY_SEPARATOR, $charset ) * -1 ) != DIRECTORY_SEPARATOR ) |
| 1010 |
$destination .= DIRECTORY_SEPARATOR; |
| 1011 |
|
| 1012 |
if ( substr( $subdir, -1 ) != "/" ) |
| 1013 |
$subdir .= "/"; |
| 1014 |
// Extract files |
| 1015 |
for ( $i = 0; $i < $this->numFiles; $i++ ) { |
| 1016 |
$filename = $this->getNameIndex( $i ); |
| 1017 |
|
| 1018 |
if ( substr( $filename, 0, mb_strlen( $subdir, $charset ) ) == $subdir ) { |
| 1019 |
$relativePath = substr( $filename, mb_strlen( $subdir, $charset ) ); |
| 1020 |
$relativePath = str_replace( array( "/", "\\" ), DIRECTORY_SEPARATOR, $relativePath ); |
| 1021 |
|
| 1022 |
if ( mb_strlen( $relativePath, $charset ) > 0 ) { |
| 1023 |
if ( substr( $filename, -1 ) == "/" ) { |
| 1024 |
if ( ! is_dir( $destination . $relativePath ) ) |
| 1025 |
if ( ! @mkdir( $destination . $relativePath, 0755, true ) ) |
| 1026 |
$errors[$i] = $filename; |
| 1027 |
} else { |
| 1028 |
if ( dirname( $relativePath) != "." ) { |
| 1029 |
if ( ! is_dir( $destination . dirname( $relativePath ) ) ) { |
| 1030 |
// New dir (for file) |
| 1031 |
@mkdir( $destination . dirname( $relativePath ), 0755, true ); |
| 1032 |
} |
| 1033 |
} |
| 1034 |
// New file |
| 1035 |
if ( @file_put_contents( $destination . $relativePath, $this->getFromIndex( $i ) ) === false ) |
| 1036 |
$errors[$i] = $filename; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
} |
| 1040 |
} |
| 1041 |
return $errors; |
| 1042 |
} |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
/** |
| 1047 |
* Download Zip |
| 1048 |
*/ |
| 1049 |
if ( ! function_exists( 'pdfprnt_download_zip' ) ) { |
| 1050 |
function pdfprnt_download_zip( $zip_file, $upload_dir ) { |
| 1051 |
/* check permissions */ |
| 1052 |
if ( is_writable( $upload_dir ) ) { |
| 1053 |
/* load ZIP-archive */ |
| 1054 |
$result = array(); |
| 1055 |
$fp = fopen( $zip_file, 'w+'); |
| 1056 |
$curl = curl_init(); |
| 1057 |
$curl_parametres = array( |
| 1058 |
CURLOPT_URL => 'http://www.mpdfonline.com/repos/MPDF_6_0.zip', |
| 1059 |
CURLOPT_FILE => $fp, |
| 1060 |
CURLOPT_USERAGENT => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0" ) |
| 1061 |
); |
| 1062 |
curl_setopt_array( $curl, $curl_parametres ); |
| 1063 |
if ( curl_exec( $curl ) ) { |
| 1064 |
$result['done'] = 'ok'; |
| 1065 |
} else { |
| 1066 |
$result['error'] = curl_error( $curl ) . '<br />' . __( 'Check your internet connection', 'pdf-print' ); |
| 1067 |
} |
| 1068 |
curl_close( $curl ); |
| 1069 |
fclose( $fp ); |
| 1070 |
} else { |
| 1071 |
$result['error'] = __( 'Cannot load files in to "uploads" folder. Check your permissions', 'pdf-print' ); |
| 1072 |
} |
| 1073 |
return $result; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
/** |
| 1078 |
* Copy neccesary fonts to mpdf/ttfonts |
| 1079 |
* @param string $zip_file path to zip archive |
| 1080 |
*/ |
| 1081 |
if ( ! function_exists( 'pdfprnt_copy_fonts' ) ) { |
| 1082 |
function pdfprnt_copy_fonts( $zip_file, $upload_dir ) { |
| 1083 |
global $pdfprnt_options_array; |
| 1084 |
if ( empty( $pdfprnt_options_array ) ) |
| 1085 |
$pdfprnt_options_array = get_option( 'pdfprnt_options_array' ); |
| 1086 |
$destination = $upload_dir .'/pdf-print-fonts'; |
| 1087 |
if ( ! file_exists( $destination ) ) { |
| 1088 |
mkdir( $destination, 0755, true ); |
| 1089 |
} |
| 1090 |
$result = array(); |
| 1091 |
/* check permissions */ |
| 1092 |
if ( is_writable( $destination ) ) { |
| 1093 |
$zip = new Pdfprnt_ZipArchive(); |
| 1094 |
/* open zip-archive */ |
| 1095 |
if ( true === $zip->open( $zip_file ) ) { |
| 1096 |
/* extract folder with fonts */ |
| 1097 |
$errors = $zip->extractSubdirTo( $destination, "mpdf60/ttfonts" ); |
| 1098 |
$zip->close(); |
| 1099 |
if ( empty( $errors ) ) { |
| 1100 |
$result['done'] = __( 'Additional fonts were successfully loaded', 'pdf-print' ); |
| 1101 |
unlink( $zip_file ); |
| 1102 |
} else { |
| 1103 |
$result['error'] = __( 'Some errors occur during loading files', 'pdf-print' ); |
| 1104 |
} |
| 1105 |
} else { |
| 1106 |
$result['error'] = __( 'Can not extract files from zip-archive', 'pdf-print' ); |
| 1107 |
unlink( $zip_file ); |
| 1108 |
} |
| 1109 |
} else { |
| 1110 |
$result['error'] = __( 'Cannot create "uploads/pdf-print-fonts" folder. Check your permissions', 'pdf-print' ); |
| 1111 |
} |
| 1112 |
$value = isset( $result['error'] ) ? -1 : count( scandir( $destination ) ); |
| 1113 |
pdfprnt_update_option( $value, true ); |
| 1114 |
return $result; |
| 1115 |
} |
| 1116 |
} |
| 1117 |
|
| 1118 |
/** |
| 1119 |
* Download ZIP-archive with MPDF library, |
| 1120 |
* copy fonts to folder 'pdf-print-fons' |
| 1121 |
*/ |
| 1122 |
if ( ! function_exists( 'pdfprnt_load_and_copy' ) ) { |
| 1123 |
function pdfprnt_load_and_copy( $zip_file, $upload_dir ) { |
| 1124 |
$result = file_exists( $zip_file ) ? array( 'done' => 'ok' ) : pdfprnt_download_zip( $zip_file, $upload_dir ); |
| 1125 |
if ( isset( $result['done'] ) ) |
| 1126 |
$result = pdfprnt_copy_fonts( $zip_file, $upload_dir ); |
| 1127 |
return $result; |
| 1128 |
} |
| 1129 |
} |
| 1130 |
/** |
| 1131 |
* Function to load fonts for MPDF library |
| 1132 |
*/ |
| 1133 |
if ( ! function_exists( 'pdfprnt_load_fonts' ) ) { |
| 1134 |
function pdfprnt_load_fonts() { |
| 1135 |
global $pdfprnt_options_array; |
| 1136 |
if ( empty( $pdfprnt_options_array ) ) |
| 1137 |
$pdfprnt_options_array = get_option( 'pdfprnt_options_array' ); |
| 1138 |
$ajax_request = isset( $_REQUEST['action'] ) && 'pdfprnt_load_fonts' == $_REQUEST['action'] ? true : false; |
| 1139 |
$php_request = isset( $_REQUEST['pdfprnt_action'] ) && 'pdfprnt_load_fonts' == $_REQUEST['pdfprnt_action'] ? true : false; |
| 1140 |
$verified = isset( $_REQUEST['pdfprnt_ajax_nonce'] ) && wp_verify_nonce( $_REQUEST['pdfprnt_ajax_nonce'], 'pdfprnt_ajax_nonce' ) ? true : false; |
| 1141 |
if ( ( $ajax_request || $php_request ) && $verified ) { |
| 1142 |
$result = array(); |
| 1143 |
$flag = false; |
| 1144 |
/* get path to directory for ZIP-archive uploading */ |
| 1145 |
if ( is_multisite() ) { |
| 1146 |
switch_to_blog( 1 ); |
| 1147 |
$upload_dir = wp_upload_dir(); |
| 1148 |
restore_current_blog(); |
| 1149 |
} else { |
| 1150 |
$upload_dir = wp_upload_dir(); |
| 1151 |
} |
| 1152 |
$zip_file = $upload_dir['basedir'] . '/MPDF_6_0.zip'; |
| 1153 |
$destination = $upload_dir['basedir'] .'/pdf-print-fonts'; |
| 1154 |
if ( file_exists( $destination ) ) { /* if folder with fonts already exists */ |
| 1155 |
if ( is_multisite() ) { |
| 1156 |
$network_options = get_site_option( 'pdfprnt_options_array' ); /* get network options */ |
| 1157 |
if ( $network_options['additional_fonts'] == count( scandir( $destination ) ) ) { /* if all fonts was loaded successfully */ |
| 1158 |
$result['done'] = __( 'Additional fonts was successfully loaded', 'pdf-print' ); |
| 1159 |
pdfprnt_update_option( $network_options['additional_fonts'] ); |
| 1160 |
} else { /* if something wrong */ |
| 1161 |
$result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'] ); /* load fonts */ |
| 1162 |
} |
| 1163 |
} else { |
| 1164 |
$result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'] ); /* load fonts */ |
| 1165 |
} |
| 1166 |
} else { |
| 1167 |
mkdir( $destination, 0755, true ); |
| 1168 |
$result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'] ); |
| 1169 |
} |
| 1170 |
if ( $ajax_request ) |
| 1171 |
echo json_encode( $result ); |
| 1172 |
else |
| 1173 |
return $result; |
| 1174 |
} |
| 1175 |
if ( $ajax_request ) |
| 1176 |
die(); |
| 1177 |
} |
| 1178 |
} |
| 1179 |
|
| 1180 |
if ( ! function_exists( 'pdfprnt_update_option' ) ) { |
| 1181 |
function pdfprnt_update_option( $value, $update_network = false ) { |
| 1182 |
global $pdfprnt_options_array; |
| 1183 |
if ( empty( $pdfprnt_options_array ) ) |
| 1184 |
$pdfprnt_options_array = get_option( 'pdfprnt_options_array' ); |
| 1185 |
$pdfprnt_options_array['additional_fonts'] = $value; |
| 1186 |
update_option( 'pdfprnt_options_array', $pdfprnt_options_array ); |
| 1187 |
if ( $update_network ) { |
| 1188 |
$network_options = get_site_option( 'pdfprnt_options_array' ); |
| 1189 |
$network_options['additional_fonts'] = $value; |
| 1190 |
update_site_option( 'pdfprnt_options_array', $network_options ); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
if ( ! function_exists ( 'pdfprnt_plugin_banner' ) ) { |
| 1196 |
function pdfprnt_plugin_banner() { |
| 1197 |
global $hook_suffix, $pdfprnt_plugin_info, $pdfprnt_options_array; |
| 1198 |
if ( empty( $pdfprnt_options_array ) ) |
| 1199 |
$pdfprnt_options_array = get_option( 'pdfprnt_options_array' ); |
| 1200 |
if ( 'plugins.php' == $hook_suffix ) { |
| 1201 |
if ( isset( $pdfprnt_options_array['first_install'] ) && strtotime( '-1 week' ) > $pdfprnt_options_array['first_install'] ) |
| 1202 |
bws_plugin_banner( $pdfprnt_plugin_info, 'pdfprnt', 'pdf-print', 'e2f2549f4d70bc4cb9b48071169d264e', '101', '//ps.w.org/pdf-print/assets/icon-128x128.png' ); |
| 1203 |
bws_plugin_banner_to_settings( $pdfprnt_plugin_info, 'pdfprnt_options_array', 'pdf-print', 'admin.php?page=pdf-print.php' ); |
| 1204 |
} |
| 1205 |
|
| 1206 |
if ( isset( $_REQUEST['page'] ) && 'pdf-print.php' == $_REQUEST['page'] ) { |
| 1207 |
bws_plugin_suggest_feature_banner( $pdfprnt_plugin_info, 'pdfprnt_options_array', 'pdf-print' ); |
| 1208 |
} |
| 1209 |
} |
| 1210 |
} |
| 1211 |
|
| 1212 |
/* Deleting plugin options on uninstalling */ |
| 1213 |
if ( ! function_exists( 'pdfprnt_uninstall' ) ) { |
| 1214 |
function pdfprnt_uninstall() { |
| 1215 |
global $wpdb; |
| 1216 |
if ( is_multisite() ) { |
| 1217 |
/* Get all blog ids */ |
| 1218 |
$blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); |
| 1219 |
$tables = ''; |
| 1220 |
$old_blog = $wpdb->blogid; |
| 1221 |
foreach ( $blogids as $blog_id ) { |
| 1222 |
switch_to_blog( $blog_id ); |
| 1223 |
delete_option( 'pdfprnt_options_array' ); |
| 1224 |
} |
| 1225 |
switch_to_blog( $old_blog ); |
| 1226 |
delete_site_option( 'pdfprnt_options_array' ); |
| 1227 |
} else { |
| 1228 |
delete_option( 'pdfprnt_options_array' ); |
| 1229 |
} |
| 1230 |
|
| 1231 |
require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); |
| 1232 |
bws_include_init( plugin_basename( __FILE__ ) ); |
| 1233 |
bws_delete_plugin( plugin_basename( __FILE__ ) ); |
| 1234 |
} |
| 1235 |
} |
| 1236 |
|
| 1237 |
/* Adding function to output PDF document or pirnt page */ |
| 1238 |
add_action( 'wp', 'pdfprnt_print' ); |
| 1239 |
add_action( 'wp_head', 'pdfprnt_auto_show_buttons_search_archive' ); |
| 1240 |
add_action( 'plugins_loaded', 'pdfprnt_plugins_loaded' ); |
| 1241 |
/* Initialization */ |
| 1242 |
add_action( 'init', 'pdfprnt_init' ); |
| 1243 |
add_action( 'admin_init', 'pdfprnt_admin_init' ); |
| 1244 |
/* Adding stylesheets */ |
| 1245 |
add_action( 'admin_enqueue_scripts', 'pdfprnt_admin_head' ); |
| 1246 |
add_action( 'wp_enqueue_scripts', 'pdfprnt_admin_head' ); |
| 1247 |
/* Adding 'BWS Plugins' admin menu */ |
| 1248 |
add_action( 'admin_menu', 'pdfprnt_add_pages' ); |
| 1249 |
/* Add query vars */ |
| 1250 |
add_filter( 'query_vars', 'print_vars_callback' ); |
| 1251 |
/* Additional links on the plugin page */ |
| 1252 |
add_filter( 'plugin_action_links', 'pdfprnt_action_links', 10, 2 ); |
| 1253 |
add_filter( 'plugin_row_meta', 'pdfprnt_links', 10, 2 ); |
| 1254 |
/* Adding buttons plugin to content */ |
| 1255 |
add_filter( 'the_content', 'pdfprnt_content' ); |
| 1256 |
/* load additional fonts */ |
| 1257 |
add_action( 'wp_ajax_pdfprnt_load_fonts', 'pdfprnt_load_fonts' ); |
| 1258 |
/* Adding banner */ |
| 1259 |
add_action( 'admin_notices', 'pdfprnt_plugin_banner' ); |
| 1260 |
/* Plugin uninstall function */ |
| 1261 |
|
| 1262 |
add_action( 'bwsplgns_display_pdf_print_buttons', 'pdfprnt_display_plugin_butttons', 10, 2 ); |
| 1263 |
register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' ); |