PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.9.1
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.9.1
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / pdf-print.php

pdf-print.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 1.9.1, at pdf-print.php

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