PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.5
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.5
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
← All changes | pdf-print.php +1066 -1279 1.9.11.5 View file →
@@ -1,1279 +1,1066 @@
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' );
1 +<?php
2 +/*
3 +Plugin Name: PDF & Print
4 +Plugin URI: http://bestwebsoft.com/plugin/
5 +Description: Plugin adds PDF creation and Print button on your site.
6 +Author: BestWebSoft
7 +Version: 1.5
8 +Author URI: http://bestwebsoft.com/
9 +License: GPLv2 or later
10 +*/
11 +
12 +/* © Copyright 2013 BestWebSoft ( http://support.bestwebsoft.com )
13 +
14 + This program is free software; you can redistribute it and/or modify
15 + it under the terms of the GNU General Public License, version 2, as
16 + published by the Free Software Foundation.
17 +
18 + This program is distributed in the hope that it will be useful,
19 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 + GNU General Public License for more details.
22 +
23 + You should have received a copy of the GNU General Public License
24 + along with this program; if not, write to the Free Software
25 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 +*/
27 +
28 +require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
29 +
30 +/* Add our own menu */
31 +if ( ! function_exists( 'pdfprnt_add_pages' ) ) {
32 + function pdfprnt_add_pages() {
33 + add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', WP_CONTENT_URL . "/plugins/google-plus-one/images/px.png", 1001 );
34 + add_submenu_page( 'bws_plugins', __( 'PDF & Print Settings', 'pdf-print' ), __( 'PDF & Print', 'pdf-print' ), 'manage_options', "pdf-print.php", 'pdfprnt_settings_page' );
35 + }
36 +}
37 +
38 +/* Register settings for plugin */
39 +if ( ! function_exists( 'pdfprnt_settings' ) ) {
40 + function pdfprnt_settings() {
41 + global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wpmu;
42 + $pdfprnt_output_count_buttons = 0; /* Variable to verify performance number of once function. */
43 + $pdfprnt_default_post_types = array();
44 + foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1, '_builtin' => true ), 'names' ) as $value )
45 + $pdfprnt_default_post_types[] = $value; /* Default post types of WordPress. */
46 + $pdfprnt_options_array_defaults = array(
47 + 'position' => 'top-right',
48 + 'position_search_archive' => 'left',
49 + 'position_custom' => 'left',
50 + 'show_btn_print' => 1,
51 + 'show_btn_pdf' => 1,
52 + 'show_btn_print_search_archive' => 1,
53 + 'show_btn_pdf_search_archive' => 1,
54 + 'show_btn_print_custom' => 1,
55 + 'show_btn_pdf_custom' => 1,
56 + 'use_theme_stylesheet' => 0,
57 + 'tmpl_post' => 1,
58 + 'tmpl_search' => 1,
59 + 'tmpl_custom' => 1,
60 + 'tmpl_shorcode' => 1,
61 + 'use_types_posts' => $pdfprnt_default_post_types
62 + );
63 + if ( 1 == $wpmu ) {
64 + if ( ! get_site_option( 'pdfprnt_options_array' ) ) {
65 + add_site_option( 'pdfprnt_options_array', $cptch_option_defaults, '', 'yes' );
66 + }
67 + } else {
68 + if ( ! get_option( 'pdfprnt_options_array' ) )
69 + add_option( 'pdfprnt_options_array', $pdfprnt_options_array_defaults, '', 'yes' );
70 + }
71 + if ( 1 == $wpmu )
72 + $pdfprnt_options_array = get_site_option( 'pdfprnt_options_array' );
73 + else
74 + $pdfprnt_options_array = get_option( 'pdfprnt_options_array' );
75 + $pdfprnt_options_array = array_merge( $pdfprnt_options_array_defaults, $pdfprnt_options_array );
76 + }
77 +}
78 +
79 +/* Function check if plugin is compatible with current WP version */
80 +if ( ! function_exists ( 'pdfprnt_version_check' ) ) {
81 + function pdfprnt_version_check() {
82 + global $wp_version;
83 + $plugin_data = get_plugin_data( __FILE__, false );
84 + $require_wp = "3.0"; /* Wordpress at least requires version */
85 + $plugin = plugin_basename( __FILE__ );
86 + if ( version_compare( $wp_version, $require_wp, "<" ) ) {
87 + if ( is_plugin_active( $plugin ) ) {
88 + deactivate_plugins( $plugin );
89 + wp_die( "<strong>" . $plugin_data['Name'] . " </strong> " . __( 'requires', 'pdf-print' ) . " <strong>WordPress" . $require_wp . " </strong> " . __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'pdf-print') . "<br /><br />" . __( 'Back to the WordPress', 'pdf-print') . " <a href='" . get_admin_url( null, 'plugins.php' ) . "'>" . __( 'Plugins page', 'pdf-print') . "</a>." );
90 + }
91 + }
92 + }
93 +}
94 +
95 +/* Add admin page */
96 +if ( ! function_exists ( 'pdfprnt_settings_page' ) ) {
97 + function pdfprnt_settings_page () {
98 + global $pdfprnt_options_array;
99 + $pdfprnt_positions_values = array(
100 + 'top-left' => __( 'Top Left', 'pdf-print' ),
101 + 'top-right' => __( 'Top Right', 'pdf-print' ),
102 + 'bottom-left' => __( 'Bottom Left', 'pdf-print' ),
103 + 'bottom-right' => __( 'Bottom Right', 'pdf-print' )
104 + );
105 + if ( isset( $_REQUEST['pdfprnt_position'] ) &&
106 + isset( $_REQUEST['pdfprnt_position_search_archive'] ) &&
107 + isset( $_REQUEST['pdfprnt_position_custom'] ) &&
108 + isset( $_REQUEST['pdfprnt_use_theme_stylesheet'] ) &&
109 + isset( $_REQUEST['pdfprnt_tmpl_post'] ) &&
110 + isset( $_REQUEST['pdfprnt_tmpl_custom'] ) &&
111 + isset( $_REQUEST['pdfprnt_tmpl_search'] ) &&
112 + check_admin_referer( plugin_basename( __FILE__ ), 'pdfprnt_nonce_name' ) ) {
113 + $pdfprnt_options_array['position'] = $_REQUEST['pdfprnt_position'];
114 + $pdfprnt_options_array['position_search_archive'] = $_REQUEST['pdfprnt_position_search_archive'];
115 + $pdfprnt_options_array['position_custom'] = $_REQUEST['pdfprnt_position_custom'];
116 + $pdfprnt_options_array['tmpl_post'] = $_REQUEST['pdfprnt_tmpl_post'];
117 + $pdfprnt_options_array['tmpl_search'] = $_REQUEST['pdfprnt_tmpl_search'];
118 + $pdfprnt_options_array['tmpl_custom'] = $_REQUEST['pdfprnt_tmpl_custom'];
119 + $pdfprnt_options_array['use_theme_stylesheet'] = $_REQUEST['pdfprnt_use_theme_stylesheet'];
120 + $pdfprnt_options_array['show_btn_pdf'] = isset( $_REQUEST['pdfprnt_show_btn_pdf'] ) ? 1 : 0;
121 + $pdfprnt_options_array['show_btn_print'] = isset( $_REQUEST['pdfprnt_show_btn_print'] ) ? 1 : 0;
122 + $pdfprnt_options_array['show_btn_pdf_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_search_archive'] ) ? 1 : 0;
123 + $pdfprnt_options_array['show_btn_print_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_print_search_archive'] ) ? 1 : 0;
124 + $pdfprnt_options_array['show_btn_pdf_custom'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_custom'] ) ? 1 : 0;
125 + $pdfprnt_options_array['show_btn_print_custom'] = isset( $_REQUEST['pdfprnt_show_btn_print_custom'] ) ? 1 : 0;
126 + $pdfprnt_options_array['tmpl_shorcode'] = isset( $_REQUEST['pdfprnt_tmpl_shorcode'] ) ? 1 : 0;
127 + $pdfprnt_options_array['use_types_posts'] = isset( $_REQUEST['pdfprnt_use_types_posts'] ) ? $_REQUEST['pdfprnt_use_types_posts'] : array();
128 + update_option ( 'pdfprnt_options_array', $pdfprnt_options_array );
129 + $message = __( 'Settings saved.', 'pdf-print' );
130 + } ?>
131 + <div class="wrap">
132 + <div class="icon32 icon32-bws" id="icon-options-general"></div>
133 + <h2><?php echo __( 'PDF & Print Settings', 'pdf-print' ); ?></h2>
134 + <div class="updated fade" <?php if( empty( $message ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
135 + <div>
136 + <form method="post" action="admin.php?page=pdf-print.php">
137 + <table class="form-table pdfprnt_settings_table">
138 + <tr>
139 + <th scope="row"><?php echo __( 'Use of theme stylesheet or plugin default style:', 'pdf-print' ); ?></th>
140 + <td>
141 + <select name="pdfprnt_use_theme_stylesheet">
142 + <option value="0" <?php if ( 0 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Default stylesheet', 'pdf-print' ); ?></option>
143 + <option value="1" <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Current theme stylesheet', 'pdf-print' ); ?></option>
144 + </select>
145 + </td>
146 + </tr>
147 + <tr>
148 + <th scope="row"><?php echo __( 'The types of posts that the plugin will use:', 'pdf-print' ); ?></th>
149 + <td>
150 + <select name="pdfprnt_use_types_posts[]" multiple="multiple">
151 + <?php foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1 ), 'objects' ) as $key => $value ) : ?>
152 + <option value="<?php echo $key; ?>" <?php if ( in_array( $key, $pdfprnt_options_array['use_types_posts'] ) ) echo 'selected="selected"'; ?>><?php echo $value->label; ?></option>
153 + <?php endforeach; ?>
154 + </select>
155 + </td>
156 + </tr>
157 + <?php
158 + $active_plugins = get_option( 'active_plugins' );
159 + if( 0 < count( preg_grep( '/portfolio\/portfolio.php/', $active_plugins ) ) ) : ?>
160 + <tr>
161 + <th scope="row"></th>
162 + <td>
163 + <span class="pdfprnt_explanation"><?php echo __( 'If you are using a Portfolio plugin (powered by bestwebsoft.com) and you need the output pdf and print buttons next to each post, you just need to insert the strings in loop into the template source code in files portfolio.php and portfolio-post.php', 'pdf-print' ) . ' &#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_bws_portfolio_post\' ) ) echo pdfprnt_show_buttons_for_bws_portfolio_post(); ?&#62;<br/> ' . __( ' In order to use PDF and Print buttons for all posts you need to put the strings below into the template source code in file portfolio.php', 'pdf-print' ) . ' &#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_bws_portfolio\' ) ) echo pdfprnt_show_buttons_for_bws_portfolio(); ?&#62;'; ?></span>
164 + </td>
165 + </tr>
166 + <?php endif; ?>
167 + <tr>
168 + <th scope="row">
169 + <?php echo __( 'Position of buttons in content:', 'pdf-print' ); ?>
170 + </th>
171 + <td>
172 + <select name="pdfprnt_position">
173 + <?php foreach ( $pdfprnt_positions_values as $key => $value ) : ?>
174 + <option value="<?php echo $key; ?>" <?php if ( $pdfprnt_options_array['position'] == $key ) echo 'selected="selected"'; ?>><?php echo $value; ?></option>
175 + <?php endforeach; ?>
176 + </select>
177 + </td>
178 + </tr>
179 + <tr>
180 + <th scope="row"><?php echo __( 'Show:', 'pdf-print' ); ?></th>
181 + <td>
182 + <label><input type="checkbox" name="pdfprnt_show_btn_pdf" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'PDF button', 'pdf-print' ); ?></span></label><br />
183 + <label><input type="checkbox" name="pdfprnt_show_btn_print" <?php if ( 1 == $pdfprnt_options_array['show_btn_print'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Print button', 'pdf-print' ); ?></span></label>
184 + </td>
185 + </tr>
186 + <tr>
187 + <th scope="row">
188 + <?php echo __( 'Default template setting for post:', 'pdf-print' ); ?>
189 + </th>
190 + <td>
191 + <div>
192 + <label>
193 + <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
194 + <input type="radio" name="pdfprnt_tmpl_post" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
195 + </label>
196 + </div>
197 + <div>
198 + <label>
199 + <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
200 + <input type="radio" name="pdfprnt_tmpl_post" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
201 + </label>
202 + </div>
203 + <div>
204 + <label>
205 + <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
206 + <input type="radio" name="pdfprnt_tmpl_post" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
207 + </label>
208 + </div>
209 + </td>
210 + </tr>
211 + <tr>
212 + <th scope="row">
213 + <?php echo __( 'Position of buttons in content for custom post:', 'pdf-print' ); ?>
214 + </th>
215 + <td>
216 + <select name="pdfprnt_position_custom">
217 + <option value="pdfprnt-left" <?php if ( 'left' == $pdfprnt_options_array['position_custom'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Left', 'pdf-print' ); ?></option>
218 + <option value="pdfprnt-right" <?php if ( 'right' == $pdfprnt_options_array['position_custom'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Right', 'pdf-print' ); ?></option>
219 + </select>
220 + </td>
221 + </tr>
222 + <tr>
223 + <th scope="row"><?php echo __( 'Show for custom posts:', 'pdf-print' ); ?></th>
224 + <td>
225 + <label><input type="checkbox" name="pdfprnt_show_btn_pdf_custom" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'PDF button', 'pdf-print' ); ?></span></label><br />
226 + <label><input type="checkbox" name="pdfprnt_show_btn_print_custom" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Print button', 'pdf-print' ); ?></span></label>
227 + </td>
228 + </tr>
229 + <tr>
230 + <th scope="row">
231 + <?php echo __( 'Default template setting for custom posts:', 'pdf-print' ); ?>
232 + </th>
233 + <td>
234 + <div>
235 + <label>
236 + <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
237 + <input type="radio" name="pdfprnt_tmpl_custom" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
238 + </label>
239 + </div>
240 + <div>
241 + <label>
242 + <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
243 + <input type="radio" name="pdfprnt_tmpl_custom" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
244 + </label>
245 + </div>
246 + <div>
247 + <label>
248 + <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
249 + <input type="radio" name="pdfprnt_tmpl_custom" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
250 + </label>
251 + </div>
252 + </td>
253 + </tr>
254 + <tr>
255 + <th scope="row"></th>
256 + <td>
257 + <span class="pdfprnt_explanation"><?php echo __( 'In order to use PDF and Print buttons on the custom page you should use the', 'pdf-print' ) . '&#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_custom_post_type\' ) ) echo pdfprnt_show_buttons_for_custom_post_type( $custom_query ); ?&#62;' . __( ' where you have to specify query parameters for your custom post.<br/> For example: ', 'pdf-print' ) . '&#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_custom_post_type\' ) ) echo pdfprnt_show_buttons_for_custom_post_type( \'post_type=gallery&orderby=post_date\' ); ?&#62;' . __(' or ', 'pdf-print') . '&#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_custom_post_type\' ) ) echo pdfprnt_show_buttons_for_custom_post_type( array( \'post_type\' => \'gallery\', \'orderby\' => \'post_date\' ) ); ?&#62;.' . __( ' For more information on the syntax for assigning parameters to function see <a target="_blank" href="http://codex.wordpress.org/Class_Reference/WP_Query#Parameters">here</a>.', 'pdf-print' ); ?></span>
258 + </td>
259 + </tr>
260 + <tr>
261 + <th scope="row">
262 + <?php echo __( 'Position of buttons on search or archive page:', 'pdf-print' ); ?>
263 + </th>
264 + <td>
265 + <select name="pdfprnt_position_search_archive">
266 + <option value="pdfprnt-left" <?php if ( 'left' == $pdfprnt_options_array['position_search_archive'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Left', 'pdf-print' ); ?></option>
267 + <option value="pdfprnt-right" <?php if ( 'right' == $pdfprnt_options_array['position_search_archive'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Right', 'pdf-print' ); ?></option>
268 + </select>
269 + </td>
270 + </tr>
271 + <tr>
272 + <th scope="row"><?php echo __( 'Show for search or archive page:', 'pdf-print' ); ?></th>
273 + <td>
274 + <label><input type="checkbox" name="pdfprnt_show_btn_pdf_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'PDF button', 'pdf-print' ); ?></span></label><br />
275 + <label><input type="checkbox" name="pdfprnt_show_btn_print_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Print button', 'pdf-print' ); ?></span></label>
276 + </td>
277 + </tr>
278 + <tr>
279 + <th scope="row">
280 + <?php echo __( 'Default template setting for search and archive:', 'pdf-print' ); ?>
281 + </th>
282 + <td>
283 + <div>
284 + <label>
285 + <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
286 + <input type="radio" name="pdfprnt_tmpl_search" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
287 + </label>
288 + </div>
289 + <div>
290 + <label>
291 + <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
292 + <input type="radio" name="pdfprnt_tmpl_search" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
293 + </label>
294 + </div>
295 + <div>
296 + <label>
297 + <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
298 + <input type="radio" name="pdfprnt_tmpl_search" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
299 + </label>
300 + </div>
301 + </td>
302 + </tr>
303 + <tr>
304 + <th scope="row"></th>
305 + <td>
306 + <span class="pdfprnt_explanation"><?php echo __( 'In order to use PDF and Print buttons on the search page or archive page you should put the strings below into the template source code in files search.php or archives.php ', 'pdf-print' ) . ' &#60;?php if ( function_exists( \'pdfprnt_show_buttons_search_archive\' ) ) echo pdfprnt_show_buttons_search_archive(); ?&#62;'; ?></span>
307 + </td>
308 + </tr>
309 + <tr>
310 + <th scope="row">
311 + <?php echo __( 'Settings for shorcodes:', 'pdf-print' ); ?>
312 + </th>
313 + <td>
314 + <label><input type="checkbox" name="pdfprnt_tmpl_shorcode" <?php if ( 1 == $pdfprnt_options_array['tmpl_shorcode'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Do!', 'pdf-print' ); ?></span></label>
315 + </td>
316 + </tr>
317 + <tr>
318 + <td colspan="2">
319 + <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
320 + </td>
321 + </tr>
322 + </table>
323 + <?php wp_nonce_field( plugin_basename( __FILE__ ), 'pdfprnt_nonce_name' ); ?>
324 + </form>
325 + </div>
326 + </div>
327 + <?php }
328 +}
329 +
330 +/* Positioning buttons in the page */
331 +if( ! function_exists( 'pdfprnt_content' ) ) {
332 + function pdfprnt_content( $content ) {
333 + global $pdfprnt_options_array, $post;
334 + if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) // Check for existence the type of posts.
335 + return $content;
336 + if ( 1 == $pdfprnt_options_array['show_btn_pdf'] || 1 == $pdfprnt_options_array['show_btn_print'] ) {
337 + $position = ( 'top-left' == $pdfprnt_options_array['position'] || 'top-right' == $pdfprnt_options_array['position'] ) ? true : false;
338 + $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position'] . '">';
339 + if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) {
340 + $permalink = add_query_arg( 'print' , 'pdf' , get_permalink( $post->ID ) );
341 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="View PDF" /></a>';
342 + }
343 + if ( 1 == $pdfprnt_options_array['show_btn_print'] ) {
344 + $permalink = add_query_arg( 'print' , 'print' , get_permalink( $post->ID ) );
345 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
346 + }
347 + $str .= '</div>';
348 + if ( $position )
349 + $content = $str . $content;
350 + else
351 + $content = $content . $str;
352 + unset( $position );
353 + unset( $str );
354 + }
355 + return $content;
356 + }
357 +}
358 +
359 +/* Output buttons for search or archive pages */
360 +if( ! function_exists( 'pdfprnt_show_buttons_search_archive' ) ) {
361 + function pdfprnt_show_buttons_search_archive() {
362 + global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp, $posts;
363 + if ( 0 < $pdfprnt_output_count_buttons )
364 + return;
365 + if ( 1 !== $pdfprnt_options_array['show_btn_pdf_search_archive'] && 1 !== $pdfprnt_options_array['show_btn_print_search_archive'] )
366 + return;
367 + if ( ( ! is_search() && ! is_archive() ) || ( is_category() || ! have_posts() ) )
368 + return;
369 + /* Check for existence the type of posts. */
370 + $is_return = true;
371 + foreach ( $posts as $post ) {
372 + if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
373 + $is_return = false;
374 + break;
375 + }
376 + }
377 + if ( $is_return )
378 + return;
379 + $pdfprnt_output_count_buttons++;
380 + if ( empty( $wp->request ) )
381 + $current_url = add_query_arg( $wp->query_string, '', home_url() );
382 + else
383 + $current_url = home_url( $wp->request );
384 + $str = '<div class="' . $pdfprnt_options_array['position_search_archive'] . '">';
385 + if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) {
386 + $permalink = add_query_arg( 'print' , 'pdf-page' , $current_url );
387 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
388 + }
389 + if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) {
390 + $permalink = add_query_arg( 'print' , 'print-page' , $current_url );
391 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
392 + }
393 + $str .= '</div>';
394 + unset( $current_url );
395 + unset( $permalink );
396 + return $str;
397 + }
398 +}
399 +
400 +/* Output buttons of page for BWS Portfolio plugin */
401 +if( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio' ) ) {
402 + function pdfprnt_show_buttons_for_bws_portfolio() {
403 + global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp;
404 + if ( 0 < $pdfprnt_output_count_buttons )
405 + return;
406 + if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
407 + return;
408 + if ( ! in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] ) )
409 + return;
410 + $pdfprnt_output_count_buttons++;
411 + if ( empty( $wp->request ) )
412 + $current_url = add_query_arg( $wp->query_string, '', home_url() );
413 + else
414 + $current_url = home_url( $wp->request );
415 + $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
416 + if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
417 + $permalink = add_query_arg( 'print' , 'pdf-portfolio-page' , $current_url );
418 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
419 + }
420 + if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
421 + $permalink = add_query_arg( 'print' , 'print-portfolio-page' , $current_url );
422 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
423 + }
424 + $str .= '</div>';
425 + unset( $current_url );
426 + unset( $permalink );
427 + return $str;
428 + }
429 +}
430 +
431 +/* Output buttons of post for BWS Portfolio plugin */
432 +if( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio_post' ) ) {
433 + function pdfprnt_show_buttons_for_bws_portfolio_post() {
434 + global $pdfprnt_options_array, $post;
435 + if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
436 + return;
437 + if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
438 + return;
439 + $current_url = get_permalink();
440 + $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
441 + if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
442 + $permalink = add_query_arg( 'print' , 'pdf-portfolio' , $current_url );
443 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
444 + }
445 + if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
446 + $permalink = add_query_arg( 'print' , 'print-portfolio' , $current_url );
447 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
448 + }
449 + $str .= '</div>';
450 + unset( $current_url );
451 + unset( $permalink );
452 + return $str;
453 + }
454 +}
455 +
456 +/* Output buttons of page for custom post type */
457 +if( ! function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) {
458 + function pdfprnt_show_buttons_for_custom_post_type( $custom_query ) {
459 + global $pdfprnt_options_array, $pdfprnt_output_count_buttons;
460 + if ( 0 < $pdfprnt_output_count_buttons )
461 + return;
462 + if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
463 + return;
464 + if ( ! is_array( $custom_query ) && ! is_string( $custom_query ) )
465 + return;
466 + $custom_query = new WP_Query( $custom_query );
467 + /* Check for existence the type of posts. */
468 + $is_return = true;
469 + foreach ( $custom_query->posts as $post ) {
470 + if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
471 + $is_return = false;
472 + break;
473 + }
474 + }
475 + if ( $is_return )
476 + return;
477 + $pdfprnt_output_count_buttons++;
478 + $current_url = add_query_arg( $custom_query->query, '', home_url() );
479 + $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
480 + if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
481 + $permalink = add_query_arg( 'print' , 'pdf-custom-page' , $current_url );
482 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
483 + }
484 + if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
485 + $permalink = add_query_arg( 'print' , 'print-custom-page' , $current_url );
486 + $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
487 + }
488 + $str .= '</div>';
489 + unset( $current_url );
490 + unset( $permalink );
491 + unset( $is_return );
492 + unset( $custom_query );
493 + return $str;
494 + }
495 +}
496 +
497 +/* Add links */
498 +if ( ! function_exists( 'pdfprnt_action_links' ) ) {
499 + function pdfprnt_action_links( $links, $file ) {
500 + $base = plugin_basename( __FILE__ );
501 + if ( $file == $base ) {
502 + $settings_link = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
503 + array_unshift( $links, $settings_link );
504 + }
505 + return $links;
506 + }
507 +}
508 +
509 +/* Add links */
510 +if ( ! function_exists( 'pdfprnt_links' ) ) {
511 + function pdfprnt_links( $links, $file ) {
512 + $base = plugin_basename( __FILE__ );
513 + if ( $file == $base ) {
514 + $links[] = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
515 + $links[] = '<a href="http://wordpress.org/plugins/pdf-print/faq/" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>';
516 + $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'pdf-print' ) . '</a>';
517 + }
518 + return $links;
519 + }
520 +}
521 +
522 +/* Init plugin */
523 +if ( ! function_exists ( 'pdfprnt_plugin_init' ) ) {
524 + function pdfprnt_plugin_init() {
525 + load_plugin_textdomain( 'pdf-print', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
526 + load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/bws_menu/languages/' );
527 + }
528 +}
529 +
530 +/* Add stylesheets */
531 +if ( ! function_exists ( 'pdfprnt_admin_head' ) ) {
532 + function pdfprnt_admin_head() {
533 + wp_enqueue_style( 'pdfprnt-stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
534 +
535 + if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" )
536 + wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js', __FILE__ ) );
537 + }
538 +}
539 +
540 +/* Generate templates for pdf file or print */
541 +if ( ! function_exists( 'pdfprnt_generate_template' ) ) {
542 + function pdfprnt_generate_template( $content, $template = false, $isprint = false ) {
543 + global $pdfprnt_options_array;
544 + $tmpl = isset( $_GET['tmpl'] ) ? $_GET['tmpl'] : "";
545 + ob_start(); /* Starting output buffering */
546 + ?>
547 + <html>
548 + <head>
549 + <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) : ?>
550 + <link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo( 'stylesheet_url' ); ?>" media="all" />
551 + <?php else: ?>
552 + <link type="text/css" rel="stylesheet" href="<?php echo plugins_url( 'css/default.css', __FILE__ ); ?>" media="all" />
553 + <?php endif;
554 + if ( ! $template )
555 + $template = $pdfprnt_options_array['tmpl_post'];
556 + switch ( $template ) { /* Using template choosed on settings page */
557 + case 1: /* Allign left template */
558 + ?>
559 + <style type="text/css">
560 + h1, h2, h3, h4, h5, h6 {
561 + text-align: left;
562 + }
563 + img {
564 + float: right;
565 + }
566 + </style>
567 + <?php
568 + break;
569 + case 2: /* Allign center template */
570 + ?>
571 + <style type="text/css">
572 + h1, h2, h3, h4, h5, h6 {
573 + text-align: center;
574 + }
575 + img {
576 + float: left;
577 + }
578 + </style>
579 + <?php
580 + break;
581 + case 3: /* Allign right template */
582 + ?>
583 + <style type="text/css">
584 + h1, h2, h3, h4, h5, h6 {
585 + text-align: right;
586 + }
587 + img {
588 + float: left;
589 + }
590 + </style>
591 + <?php
592 + break;
593 + }
594 + switch ( $tmpl ) { /* If got something by GET (from admin bar) */
595 + case 1: /* Allign left template */
596 + ?>
597 + <style type="text/css">
598 + h1, h2, h3, h4, h5, h6 {
599 + text-align: left;
600 + }
601 + img {
602 + float: right;
603 + }
604 + </style>
605 + <?php
606 + break;
607 + case 2: /* Allign center template */
608 + ?>
609 + <style type="text/css">
610 + h1, h2, h3, h4, h5, h6 {
611 + text-align: center;
612 + }
613 + img {
614 + float: left;
615 + }
616 + </style>
617 + <?php
618 + break;
619 + case 3: /* Allign right template */
620 + ?>
621 + <style type="text/css">
622 + h1, h2, h3, h4, h5, h6 {
623 + text-align: right;
624 + }
625 + img {
626 + float: left;
627 + }
628 + </style>
629 + <?php break;
630 + }
631 + if ( $isprint ) : ?>
632 + <script type="text/javascript" src="<?php echo plugins_url( 'js/pdfprnt.print.js', __FILE__ ); ?>"></script>
633 + <?php endif; ?>
634 + </head>
635 + <body>
636 + <?php echo $content; ?>
637 + </body>
638 + </html>
639 + <?php
640 + $html = ob_get_contents(); /* Getting output buffering */
641 + ob_end_clean(); /* Closing output buffering */
642 + return $html; /* Now we done with template */
643 + }
644 +}
645 +
646 +if ( ! function_exists( 'pdfprnt_generate_template_for_bws_portfolio' ) ) {
647 + function pdfprnt_generate_template_for_bws_portfolio() {
648 + global $post;
649 + ob_start(); /* Starting output buffering */
650 + $portfolio_options = get_option( 'prtfl_options' );
651 + $meta_values = get_post_custom( $post->ID );
652 + $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
653 + if( empty ( $post_thumbnail_id ) ) {
654 + $args = array(
655 + 'post_parent' => $post->ID,
656 + 'post_type' => 'attachment',
657 + 'post_mime_type' => 'image',
658 + 'numberposts' => 1
659 + );
660 + $attachments = get_children( $args );
661 + $post_thumbnail_id = key( $attachments );
662 + }
663 + $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
664 + $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
665 + $image_desc = get_post( $post_thumbnail_id );
666 + $image_desc = $image_desc->post_content;
667 + if( get_option( 'prtfl_postmeta_update' ) == '1' ) {
668 + $post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
669 + $date_compl = $post_meta['_prtfl_date_compl'];
670 + if( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
671 + $date_compl = explode( '/', $date_compl );
672 + $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1] . '-' . $date_compl[0] . '-' . $date_compl[2] ) );
673 + }
674 + $link = $post_meta['_prtfl_link'];
675 + $short_descr = $post_meta['_prtfl_short_descr'];
676 + } else {
677 + $date_compl = get_post_meta( $post->ID, '_prtfl_date_compl', true );
678 + if( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
679 + $date_compl = explode( '/', $date_compl );
680 + $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1] . '-' . $date_compl[0] . '-' . $date_compl[2] ) );
681 + }
682 + $link = get_post_meta( $post->ID, '_prtfl_link', true);
683 + $short_descr = $post_meta['_prtfl_short_descr'];
684 + } ?>
685 + <img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" alt="<?php echo $image_alt; ?>" />
686 + <div>
687 + <p>
688 + <strong><?php _e( 'Date of completion', 'pdf-print' ); ?>:</strong> <?php echo $date_compl; ?><br/>
689 + <strong><?php _e( 'Link', 'pdf-print' ); ?>:</strong> <a href="<?php echo $link; ?>"><?php echo $link; ?></a><br/>
690 + <strong><?php _e( 'Description', 'pdf-print' ); ?>:</strong> <?php echo $short_descr; ?><br/>
691 + </p>
692 + </div>
693 + <?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
694 + if ( is_array( $terms ) && count( $terms ) > 0 ) { ?>
695 + <div style="clear:both;">
696 + <strong><?php _e( 'Technologies', 'pdf-print' ); ?>: </strong>
697 + <?php $count = 0;
698 + foreach ( $terms as $term ) {
699 + if( 0 < $count )
700 + echo ', ';
701 + echo '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
702 + $count++;
703 + } ?>
704 + </div>
705 + <?php }
706 + $content = ob_get_contents(); /* Getting output buffering */
707 + ob_end_clean(); /* Closing output buffering */
708 + return $content; /* Now we done with template */
709 + }
710 +}
711 +
712 +/* Generate query posts for Portfolio plugin */
713 +if ( ! function_exists( 'generate_query_posts_for_portfolio' ) ) {
714 + function generate_query_posts_for_portfolio() {
715 + global $wp_query;
716 + $paged = isset( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 1;
717 + $technologies = isset( $wp_query->query_vars["technologies"] ) ? $wp_query->query_vars["technologies"] : "";
718 + if( $technologies != "" ) {
719 + $args = array(
720 + 'post_type' => 'portfolio',
721 + 'post_status' => 'publish',
722 + 'posts_per_page' => get_option('posts_per_page'),
723 + 'paged' => $paged,
724 + 'tax_query' => array(
725 + array(
726 + 'taxonomy' => 'portfolio_technologies',
727 + 'field' => 'slug',
728 + 'terms' => $technologies
729 + )
730 + )
731 + );
732 + } else {
733 + $args = array(
734 + 'post_type' => 'portfolio',
735 + 'post_status' => 'publish',
736 + 'posts_per_page' => get_option('posts_per_page'),
737 + 'paged' => $paged
738 + );
739 + }
740 + query_posts( $args );
741 + }
742 +}
743 +
744 +/* Output print page or pdf document and include plugin script */
745 +if ( ! function_exists( 'pdfprnt_print' ) ) {
746 + function pdfprnt_print( $query ) {
747 + global $pdfprnt_options_array, $posts, $post;
748 + if ( $print = get_query_var( 'print' ) ) {
749 + remove_all_filters( 'the_content' );
750 + add_filter( 'the_content', 'capital_P_dangit', 11 );
751 + add_filter( 'the_content', 'wptexturize' );
752 + add_filter( 'the_content', 'convert_smilies' );
753 + add_filter( 'the_content', 'convert_chars' );
754 + add_filter( 'the_content', 'wpautop' );
755 + if ( 1 == $pdfprnt_options_array['tmpl_shorcode'] ) {
756 + add_filter( 'the_content', 'do_shortcode' ); /* executing shorcodes on the page */
757 + } else {
758 + $pattern = get_shortcode_regex();
759 + if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) ) { /* getting all shortcodes we are using */
760 + foreach ( array_unique( $matches[0] ) as $value) {
761 + $post->post_content = str_replace( $value, "", $post->post_content ); /* replacing shorcodes to an empty string */
762 + }
763 + }
764 + }
765 + switch ( $print ) {
766 + case 'pdf': /* Content for PDF from post */
767 + include ( 'mpdf/mpdf.php' );
768 + $mpdf = new mPDF( get_bloginfo( 'charset' ) );
769 + $user_info = get_userdata( $post->post_author );
770 + $mpdf->SetAuthor( $user_info->display_name );
771 + $mpdf->SetTitle( $post->post_title );
772 + $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
773 + $html = '<div class="container">
774 + <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
775 + <div class="content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
776 + </div>';
777 + $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
778 + $mpdf->Output();
779 + unset( $user_info );
780 + unset( $html );
781 + unset( $mpdf );
782 + die();
783 + break;
784 + case 'print': /* Content for printing from post */
785 + $html = '<div class="container">
786 + <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
787 + <div class="content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
788 + </div>';
789 + echo pdfprnt_generate_template( $html, false, true );
790 + unset( $html );
791 + die();
792 + break;
793 + case 'pdf-page': /* Content for PDF from archive or searching page */
794 + $html = '';
795 + $titles = array();
796 + $authors = array();
797 + include ( 'mpdf/mpdf.php' );
798 + $mpdf = new mPDF( get_bloginfo( 'charset' ) );
799 + foreach ( $posts as $p ) {
800 + if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
801 + continue;
802 + $titles[] = $p->post_title;
803 + $user_info = get_userdata( $p->post_author );
804 + $authors[] = $user_info->display_name;
805 + $html .= '<div class="container">
806 + <div class="title"><h1><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>
807 + <div class="content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
808 + </div><br/><hr/><br/>';
809 + unset( $user_info );
810 + }
811 + $titles = array_unique( $titles );
812 + $authors = array_unique( $authors );
813 + $mpdf->SetTitle( implode( ',', $titles ) );
814 + $mpdf->SetAuthor( implode( ',', $authors ) );
815 + $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
816 + $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_search'] ) );
817 + $mpdf->Output();
818 + unset( $authors );
819 + unset( $titles );
820 + unset( $html );
821 + unset( $mpdf );
822 + die();
823 + break;
824 + case 'print-page': /* Content for printing from archive or searching page */
825 + $html = '';
826 + foreach ( $posts as $p ) {
827 + if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
828 + continue;
829 + $html .= '<div class="container">
830 + <div class="title"><h1>' . $p->post_title . '</h1></div><br/>
831 + <div class="content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
832 + </div><br/><hr/><br/>';
833 + }
834 + echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_search'], true );
835 + unset( $html );
836 + die();
837 + break;
838 + case 'pdf-portfolio': /* Content for PDF from portfolio post */
839 + include ( 'mpdf/mpdf.php' );
840 + $mpdf = new mPDF( get_bloginfo( 'charset' ) );
841 + $user_info = get_userdata( $post->post_author );
842 + $mpdf->SetAuthor( $user_info->display_name );
843 + $mpdf->SetTitle( $post->post_title );
844 + $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
845 + $html = '<div class="container">
846 + <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
847 + <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
848 + </div>';
849 + $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
850 + $mpdf->Output();
851 + unset( $html );
852 + unset( $user_info );
853 + unset( $mpdf );
854 + die();
855 + break;
856 + case 'print-portfolio': /* Content for printing from porfolio post */
857 + $html = '<div class="container">
858 + <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
859 + <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
860 + </div>';
861 + echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
862 + unset( $html );
863 + die();
864 + break;
865 + case 'pdf-portfolio-page': /* Content for PDF from portfolio page */
866 + $html = '';
867 + $titles = array();
868 + $authors = array();
869 + generate_query_posts_for_portfolio();
870 + while ( have_posts() ) {
871 + the_post();
872 + global $post;
873 + if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
874 + continue;
875 + $titles[] = $post->post_title;
876 + $user_info = get_userdata( $post->post_author );
877 + $authors[] = $user_info->display_name;
878 + $html .= '<div class="container">
879 + <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
880 + <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
881 + </div><br/><hr/><br/>';
882 + unset( $user_info );
883 + }
884 + include ( 'mpdf/mpdf.php' );
885 + $mpdf = new mPDF( get_bloginfo( 'charset' ) );
886 + $titles = array_unique( $titles );
887 + $authors = array_unique( $authors );
888 + $mpdf->SetTitle( implode( ',', $titles ) );
889 + $mpdf->SetAuthor( implode( ',', $authors ) );
890 + $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
891 + $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
892 + $mpdf->Output();
893 + unset( $authors );
894 + unset( $titles );
895 + unset( $html );
896 + unset( $mpdf );
897 + die();
898 + break;
899 + case 'print-portfolio-page': /* Content for printing from portfolio page */
900 + generate_query_posts_for_portfolio();
901 + $html = '';
902 + while ( have_posts() ) {
903 + the_post();
904 + global $post;
905 + if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
906 + continue;
907 + $html .= '<div class="container">
908 + <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
909 + <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
910 + </div><br/><hr/><br/>';
911 + }
912 + echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
913 + unset( $html );
914 + die();
915 + break;
916 + case 'pdf-custom-page': /* Content for PDF from custom post */
917 + $html = '';
918 + $titles = $authors = array();
919 + foreach ( $posts as $p ) {
920 + if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
921 + continue;
922 + $titles[] = $p->post_title;
923 + $user_info = get_userdata( $p->post_author );
924 + $authors[] = $user_info->display_name;
925 + $html .= '<div class="container">';
926 + $html .= '<div class="title"><h1><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>';
927 + $html .= '<div class="content">';
928 + if ( has_post_thumbnail( $p->ID ) )
929 + $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );
930 + $html .= apply_filters( 'the_content', $p->post_content ) . '</div></div><br/><hr/><br/>';
931 + unset( $user_info );
932 + }
933 + include ( 'mpdf/mpdf.php' );
934 + $mpdf = new mPDF( get_bloginfo( 'charset' ) );
935 + $titles = array_unique( $titles );
936 + $authors = array_unique( $authors );
937 + $mpdf->SetTitle( implode( ',', $titles ) );
938 + $mpdf->SetAuthor( implode( ',', $authors ) );
939 + $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
940 + $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
941 + $mpdf->Output();
942 + unset( $authors );
943 + unset( $titles );
944 + unset( $html );
945 + unset( $mpdf );
946 + die();
947 + break;
948 + case 'print-custom-page': /* Content for printing from custom post */
949 + $html = '';
950 + foreach ( $posts as $p ) {
951 + if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
952 + continue;
953 + $html .= '<div class="container">';
954 + $html .= '<div class="title"><h1>' . $p->post_title . '</h1></div><br/>';
955 + $html .= '<div class="content">';
956 + if ( has_post_thumbnail( $p->ID ) )
957 + $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );
958 + $html .= apply_filters( 'the_content', $p->post_content ) . '</div>
959 + </div><br/><hr/><br/>';
960 + }
961 + echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
962 + unset( $html );
963 + die();
964 + break;
965 + }
966 + }
967 + }
968 +}
969 +
970 +/* Add query vars */
971 +if ( ! function_exists( 'print_vars_callback' ) ) {
972 + function print_vars_callback( $query_vars ) {
973 + $query_vars[] = 'print';
974 + $query_vars[] = 'tmpl';
975 + return $query_vars;
976 + }
977 +}
978 +
979 +/* Add custom admin bar menu */
980 +if ( ! function_exists( 'pdfprnt_admin_bar_menu' ) ) {
981 + function pdfprnt_admin_bar_menu() {
982 + global $pdfprnt_options_array, $wp_admin_bar, $wp, $posts;
983 + if ( ! is_super_admin() || ! is_admin_bar_showing() ) /* Checking user */
984 + return;
985 + if ( ( ! is_search() && ! is_archive() ) || ( is_category() || ! have_posts() ) )
986 + return;
987 + $is_return = true;
988 + foreach ( $posts as $post ) {
989 + if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
990 + $is_return = false;
991 + break;
992 + }
993 + }
994 + if ( $is_return )
995 + return;
996 + if ( empty( $wp->request ) )
997 + $current_url = add_query_arg( $wp->query_string, '', home_url() );
998 + else
999 + $current_url = home_url( $wp->request );
1000 + $permalink = add_query_arg( 'print', 'pdf-page', $current_url );
1001 + $wp_admin_bar->add_menu( array(
1002 + 'id' => 'pdfprnt-bar-menu',
1003 + 'title' => '<span class="admin-bar-menu-bws-icon"></span>PDF',
1004 + 'href' => $permalink
1005 + ) );
1006 + $template_url = add_query_arg( 'tmpl', '1', $permalink ); /* Adding parametrs to link */
1007 + $wp_admin_bar->add_menu( array(
1008 + 'parent' => 'pdfprnt-bar-menu',
1009 + 'id' => 'pdfprnt-template-1',
1010 + 'title' => '<img src="' . plugins_url( 'images/template_left.jpg', __FILE__ ) . '" alt="template_left" />',
1011 + 'href' => $template_url
1012 + ) );
1013 + $template_url = add_query_arg( 'tmpl', '2', $permalink ); /* Adding parametrs to link */
1014 + $wp_admin_bar->add_menu( array(
1015 + 'parent' => 'pdfprnt-bar-menu',
1016 + 'id' => 'pdfprnt-template-2',
1017 + 'title' => '<img src="' . plugins_url( 'images/template_center.jpg', __FILE__ ) . '" alt="template_center" />',
1018 + 'href' => $template_url
1019 + ) );
1020 + $template_url = add_query_arg( 'tmpl', '3', $permalink ); /* Adding parametrs to link */
1021 + $wp_admin_bar->add_menu( array(
1022 + 'parent' => 'pdfprnt-bar-menu',
1023 + 'id' => 'pdfprnt-template-3',
1024 + 'title' => '<img src="' . plugins_url( 'images/template_right.jpg', __FILE__ ) . '" alt="template_right" />',
1025 + 'href' => $template_url
1026 + ) );
1027 + unset( $current_url );
1028 + unset( $permalink );
1029 + unset( $template_url );
1030 + }
1031 +}
1032 +
1033 +/* Deleting plugin options on uninstalling */
1034 +if( ! function_exists( 'pdfprnt_uninstall' ) ) {
1035 + function pdfprnt_uninstall() {
1036 + delete_option( 'pdfprnt_options_array' );
1037 + delete_site_option( 'pdfprnt_options_array' );
1038 + }
1039 +}
1040 +
1041 +/* Adding function to output PDF document or pirnt page */
1042 +add_action( 'wp', 'pdfprnt_print' );
1043 +/* Initialization default plugin settings */
1044 +add_action( 'init', 'pdfprnt_settings' );
1045 +/* Checks version of Wordpress required for plugin */
1046 +add_action( 'admin_init', 'pdfprnt_version_check' );
1047 +/* Load internationalization */
1048 +add_action( 'init', 'pdfprnt_plugin_init' );
1049 +/* Adding stylesheets */
1050 +add_action( 'init', 'pdfprnt_admin_head' );
1051 +/* Adding 'BWS Plugins' admin menu */
1052 +add_action( 'admin_menu', 'pdfprnt_add_pages' );
1053 +/* Add menu to bar menu WordPress */
1054 +add_action( 'admin_bar_menu', 'pdfprnt_admin_bar_menu', 1000 );
1055 +
1056 +/* Add query vars */
1057 +add_filter( 'query_vars', 'print_vars_callback' );
1058 +/* Adds "Settings" link to the plugin action page */
1059 +add_filter( 'plugin_action_links', 'pdfprnt_action_links', 10, 2 );
1060 +/* Additional links on the plugin page */
1061 +add_filter( 'plugin_row_meta', 'pdfprnt_links', 10, 2 );
1062 +/* Adding buttons plugin to content */
1063 +add_filter( 'the_content', 'pdfprnt_content' );
1064 +
1065 +register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' );
1066 +?>