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

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

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