PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.8.2
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.8.2
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.2, at pdf-print.php

1,434 lines 62.7 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.2
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.1" );
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_output_count_buttons, $pdfprnt_plugin_info;
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_output_count_buttons = 0;
83 $pdfprnt_default_post_types = array();
84 /* Default post types of WordPress. */
85 foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1, '_builtin' => true ), 'names' ) as $value )
86 $pdfprnt_default_post_types[] = $value;
87
88 $pdfprnt_options_array_defaults = array(
89 'plugin_option_version' => $pdfprnt_plugin_info["Version"],
90 'position' => 'top-right',
91 'position_search_archive' => 'top-right',
92 'position_custom' => 'right',
93 'show_btn_print' => 1,
94 'show_btn_pdf' => 1,
95 'show_btn_print_search_archive' => 1,
96 'show_btn_pdf_search_archive' => 1,
97 'show_btn_print_custom' => 1,
98 'show_btn_pdf_custom' => 1,
99 'use_theme_stylesheet' => 0,
100 'tmpl_shorcode' => 1,
101 'use_types_posts' => $pdfprnt_default_post_types,
102 'show_print_window' => 0,
103 'additional_fonts' => 0
104 );
105
106 if ( ! get_option( 'pdfprnt_options_array' ) )
107 add_option( 'pdfprnt_options_array', $pdfprnt_options_array_defaults );
108
109 $pdfprnt_options_array = get_option( 'pdfprnt_options_array' );
110
111 if ( ! isset( $pdfprnt_options_array['plugin_option_version'] ) || $pdfprnt_options_array['plugin_option_version'] != $pdfprnt_plugin_info["Version"] ) {
112 if ( in_array( $pdfprnt_options_array['position_search_archive'], array( 'pdfprnt-right', 'pdfprnt-left' ) ) )
113 $pdfprnt_options_array['position_search_archive'] = 'pdfprnt-left' == $pdfprnt_options_array['position_search_archive'] ? 'top-left' : 'top-right';
114 if ( in_array( $pdfprnt_options_array['position_custom'], array( 'pdfprnt-right', 'pdfprnt-left' ) ) )
115 $pdfprnt_options_array['position_custom'] = 'pdfprnt-left' == $pdfprnt_options_array['position_custom'] ? 'left' : 'right';
116 $pdfprnt_options_array = array_merge( $pdfprnt_options_array_defaults, $pdfprnt_options_array );
117 $pdfprnt_options_array['plugin_option_version'] = $pdfprnt_plugin_info["Version"];
118 update_option( 'pdfprnt_options_array', $pdfprnt_options_array );
119 }
120 }
121 }
122
123 /**
124 * Display <select> on settings page
125 **/
126 if ( ! function_exists( 'pdfprnt_display_select' ) ) {
127 function pdfprnt_display_select( $name, $selected ) {
128 $positions_values = array(
129 'top-left' => __( 'Top Left', 'pdf-print' ),
130 'top-right' => __( 'Top Right', 'pdf-print' ),
131 'bottom-left' => __( 'Bottom Left', 'pdf-print' ),
132 'bottom-right' => __( 'Bottom Right', 'pdf-print' )
133 );
134 foreach( $positions_values as $key => $value ) { ?>
135 <label><input type="radio" name="<?php echo $name; ?>" value="<?php echo $key ?>"<?php echo $key == $selected ? ' checked="checked"' : ''; ?> />&nbsp;<?php echo $value; ?></label><br/>
136 <?php }
137 }
138 }
139 /* Add admin page */
140 if ( ! function_exists ( 'pdfprnt_settings_page' ) ) {
141 function pdfprnt_settings_page () {
142 global $pdfprnt_options_array, $wp_version, $pdfprnt_plugin_info;
143 $message = $error = "";
144 $plugin_basename = plugin_basename( __FILE__ );
145 if ( is_multisite() ) {
146 switch_to_blog( 1 );
147 $upload_dir = wp_upload_dir();
148 restore_current_blog();
149 } else {
150 $upload_dir = wp_upload_dir();
151 }
152 $need_fonts_reload = false;
153 $fonts_path = $upload_dir['basedir'] .'/pdf-print-fonts';
154 if ( ! function_exists( 'get_plugins' ) )
155 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
156 $all_plugins = get_plugins();
157 if ( isset( $_REQUEST['pdfprnt_form_submit'] ) && check_admin_referer( $plugin_basename, 'pdfprnt_nonce_name' ) ) {
158 $pdfprnt_options_array['position'] = isset( $_REQUEST['pdfprnt_position'] ) ? $_REQUEST['pdfprnt_position'] : 'top-right';
159 $pdfprnt_options_array['position_search_archive'] = isset( $_REQUEST['pdfprnt_position_search_archive'] ) ? $_REQUEST['pdfprnt_position_search_archive'] : 'top-right';
160 $pdfprnt_options_array['position_custom'] = isset( $_REQUEST['pdfprnt_position_custom'] ) ? $_REQUEST['pdfprnt_position_custom'] : 'right';
161 $pdfprnt_options_array['use_theme_stylesheet'] = isset( $_REQUEST['pdfprnt_use_theme_stylesheet'] ) ? $_REQUEST['pdfprnt_use_theme_stylesheet'] : 0;
162 $pdfprnt_options_array['show_btn_pdf'] = isset( $_REQUEST['pdfprnt_show_btn_pdf'] ) ? 1 : 0;
163 $pdfprnt_options_array['show_btn_print'] = isset( $_REQUEST['pdfprnt_show_btn_print'] ) ? 1 : 0;
164 $pdfprnt_options_array['show_btn_pdf_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_search_archive'] ) ? 1 : 0;
165 $pdfprnt_options_array['show_btn_print_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_print_search_archive'] ) ? 1 : 0;
166 $pdfprnt_options_array['show_btn_pdf_custom'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_custom'] ) ? 1 : 0;
167 $pdfprnt_options_array['show_btn_print_custom'] = isset( $_REQUEST['pdfprnt_show_btn_print_custom'] ) ? 1 : 0;
168 $pdfprnt_options_array['tmpl_shorcode'] = isset( $_REQUEST['pdfprnt_tmpl_shorcode'] ) ? 1 : 0;
169 $pdfprnt_options_array['show_print_window'] = isset( $_REQUEST['pdfprnt_show_print_window'] ) ? 1 : 0;
170 $pdfprnt_options_array['use_types_posts'] = isset( $_REQUEST['pdfprnt_use_types_posts'] ) ? $_REQUEST['pdfprnt_use_types_posts'] : array();
171 update_option( 'pdfprnt_options_array', $pdfprnt_options_array );
172 $message = __( 'Settings saved.', 'pdf-print' );
173 }
174 if ( ( ! is_dir( $fonts_path ) ) && 0 != $pdfprnt_options_array['additional_fonts'] ) { /* if "pdf-print-fonts" folder was removed somehow */
175 $error = __( 'The folder "uploads/pdf-print-fonts" was removed.', 'pdf-print' );
176 $need_fonts_reload = true;
177 } elseif (
178 is_dir( $fonts_path ) &&
179 $pdfprnt_options_array['additional_fonts'] != count( scandir( $fonts_path ) ) &&
180 0 < $pdfprnt_options_array['additional_fonts']
181 ) { /* if some fonts was removed somehow from "pdf-print-fonts" folder */
182 $error = __( 'Some fonts were removed from the folder "uploads/pdf-print-fonts".', 'pdf-print' );
183 $need_fonts_reload = true;
184 }
185 if ( $need_fonts_reload ) {
186 $error .= __( ' You may need to reload fonts.', 'pdf-print' );
187 $pdfprnt_options_array['additional_fonts'] = 0;
188 }
189 if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
190 /* GO PRO */
191 $go_pro_result = bws_go_pro_tab_check( $plugin_basename );
192 if ( ! empty( $go_pro_result['error'] ) )
193 $error = $go_pro_result['error'];
194 }
195 if ( isset( $_REQUEST['pdfprnt_load_fonts'] ) ) {
196 /* load additional fonts if javascript is disabled */
197 $result = pdfprnt_load_fonts();
198 if ( isset( $result['error'] ) )
199 $error .= '&nbsp;' . $result['error'];
200 if ( isset( $result['done'] ) )
201 $message .= '&nbsp;' . $result['done'];
202 } ?>
203 <div class="wrap">
204 <div class="icon32 icon32-bws" id="icon-options-general"></div>
205 <h2><?php _e( 'PDF & Print Settings', 'pdf-print' ); ?></h2>
206 <h2 class="nav-tab-wrapper">
207 <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>
208 <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>
209 <a class="nav-tab" href="http://bestwebsoft.com/products/pdf-print/faq/" target="_blank"><?php _e( 'FAQ', 'pdf-print' ); ?></a>
210 <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>
211 </h2>
212 <div class="updated fade" <?php if ( empty( $message ) || "" != $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
213 <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>
214 <div class="error" <?php if ( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
215 <?php if ( ! isset( $_GET['action'] ) ) { ?>
216 <form method="post" action="admin.php?page=pdf-print.php" id="pdfprnt_settings_form">
217 <table class="form-table pdfprnt_settings_table">
218 <tr id="pdfprnt_load_fonts_button">
219 <th scope="row"><?php _e( 'Load additional fonts', 'pdf-print' ); ?></th>
220 <td style="position: relative;">
221 <?php if ( 0 == $pdfprnt_options_array['additional_fonts'] && class_exists( 'ZipArchive' ) ) {
222 $ajax_nonce = wp_create_nonce( 'pdfprnt_ajax_nonce' ); ?>
223 <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 />
224 <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>
225 <input type="hidden" name="pdfprnt_action" value="pdfprnt_load_fonts" />
226 <input type="hidden" name="pdfprnt_ajax_nonce" value="<?php echo $ajax_nonce; ?>" />
227 <?php } elseif ( 0 == $pdfprnt_options_array['additional_fonts'] && ! class_exists( 'ZipArchive' ) ) { ?>
228 <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>
229 <?php } elseif ( 1 == $pdfprnt_options_array['additional_fonts'] ) { ?>
230 <span><?php _e( 'Additional fonts were loaded successfully', 'pdf-print' ); ?>.</span>
231 <?php } ?>
232 </td>
233 </tr>
234 <tr>
235 <th scope="row"><?php _e( 'Use the theme stylesheet or plugin default style', 'pdf-print' ); ?></th>
236 <td>
237 <select name="pdfprnt_use_theme_stylesheet">
238 <option value="0" <?php if ( 0 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Default stylesheet', 'pdf-print' ); ?></option>
239 <option value="1" <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Current theme stylesheet', 'pdf-print' ); ?></option>
240 </select>
241 </td>
242 </tr>
243 <tr>
244 <th scope="row"><?php _e( 'Types of posts that will be used in the plugin', 'pdf-print' ); ?></th>
245 <td>
246 <select name="pdfprnt_use_types_posts[]" multiple="multiple">
247 <?php foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1 ), 'objects' ) as $key => $value ) :
248 if ( 'attachment' != $key ) { ?>
249 <option value="<?php echo $key; ?>" <?php if ( in_array( $key, $pdfprnt_options_array['use_types_posts'] ) ) echo 'selected="selected"'; ?>><?php echo $value->label; ?></option>
250 <?php }
251 endforeach; ?>
252 </select>
253 </td>
254 </tr>
255 </table>
256 <table class="form-table pdfprnt_settings_table pdfprnt_buttons" style="width: auto !important;">
257 <tr class="pdfprnt_table_head">
258 <th scope="row"></th>
259 <th><?php _e( 'Posts and pages', 'pdf-print' ); ?></th>
260 <th><?php _e( 'Search and archive pages', 'pdf-print' ); ?></th>
261 <th><?php _e( 'Function call', 'pdf-print' ); ?></th>
262 </tr>
263 <tr class="pdfprnt_pdf_buttton">
264 <th scope="row"><?php _e( 'Show PDF button', 'pdf-print' ); ?></th>
265 <td>
266 <input type="checkbox" name="pdfprnt_show_btn_pdf" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) echo 'checked="checked"'; ?> />
267 </td>
268 <td>
269 <input type="checkbox" name="pdfprnt_show_btn_pdf_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) echo 'checked="checked"'; ?> />
270 </td>
271 <td>
272 <input type="checkbox" name="pdfprnt_show_btn_pdf_custom" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) echo 'checked="checked"'; ?> />
273 </td>
274 </tr>
275 <tr class="pdfprnt_print_buttton">
276 <th scope="row"><?php _e( 'Show Print button', 'pdf-print' ); ?></th>
277 <td>
278 <input type="checkbox" name="pdfprnt_show_btn_print" <?php if ( 1 == $pdfprnt_options_array['show_btn_print'] ) echo 'checked="checked"'; ?> />
279 </td>
280 <td>
281 <input type="checkbox" name="pdfprnt_show_btn_print_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) echo 'checked="checked"'; ?> />
282 </td>
283 <td>
284 <input type="checkbox" name="pdfprnt_show_btn_print_custom" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) 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 <?php pdfprnt_display_select( 'pdfprnt_position', $pdfprnt_options_array['position'] ); ?>
291 </td>
292 <td>
293 <?php pdfprnt_display_select( 'pdfprnt_position_search_archive', $pdfprnt_options_array['position_search_archive'] ); ?>
294 </td>
295 <td>
296
297 <label><input type="radio" name="pdfprnt_position_custom" value="left"<?php echo 'left' == $pdfprnt_options_array['position_custom'] ? ' checked="checked"' : ''; ?>>&nbsp;<?php _e( 'Left', 'pdf-print' ); ?></label><br/>
298 <label><input type="radio" name="pdfprnt_position_custom" value="right"<?php echo 'right' == $pdfprnt_options_array['position_custom'] ? ' checked="checked"' : ''; ?>>&nbsp;<?php _e( 'Right', 'pdf-print' ); ?></label>
299 </td>
300 </tr>
301 </table>
302 <div>
303 <p>
304 <?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>
305 </p>
306 </div>
307 <table class="form-table pdfprnt_settings_table">
308 <tr>
309 <th scope="row">
310 <?php _e( 'Settings for shortcodes', 'pdf-print' ); ?>
311 </th>
312 <td>
313 <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>
314 </td>
315 </tr>
316 <tr>
317 <th scope="row"><?php _e( 'Show the print window', 'pdf-print' ); ?></th>
318 <td>
319 <input type="checkbox" name="pdfprnt_show_print_window" <?php if ( 1 == $pdfprnt_options_array['show_print_window'] ) echo 'checked="checked"'; ?> />
320 </td>
321 </tr>
322 </table>
323 <div class="bws_pro_version_bloc">
324 <div class="bws_pro_version_table_bloc">
325 <div class="bws_table_bg"></div>
326 <table class="form-table bws_pro_version">
327 <tr>
328 <th scope="row"><?php _e( 'PDF files name', 'pdf-print' ); ?></th>
329 <td>
330 <label><input disabled="disabled" type="radio" name="pdfprntpr_select_file_name" value="1" /> <?php _e( 'use post or page slug', 'pdf-print' ); ?></label><br />
331 <input type="radio" disabled="disabled" name="pdfprntpr_select_file_name" value="0" /><input disabled="disabled" type="text" name='pdfprntpr_file_name' value="mpdf" /><br />
332 <span class="pdfprnt_info">
333 <?php _e( 'File name cannot contain more than 195 symbols. The file name can include Latin letters, numbers and symbols "-" , "_" only.', 'pdf-print' ) ?>
334 </span>
335 </td>
336 </tr>
337 <tr>
338 <th scope="row"><?php _e( 'Do not index pdf and print pages', 'pdf-print' ); ?></th>
339 <td>
340 <input type="checkbox" name="pdfprntpr_noindex_page" disabled="disabled" />
341 </td>
342 </tr>
343 <tr valign="top">
344 <th scope="row" colspan="2">
345 * <?php _e( 'If you upgrade to Pro version, all your settings will be saved.', 'pdf-print' ); ?>
346 </th>
347 </tr>
348 </table>
349 </div>
350 <div class="bws_pro_version_tooltip">
351 <div class="bws_info">
352 <?php _e( 'Unlock premium options by upgrading to a PRO version.', 'pdf-print' ); ?>
353 <a 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>
354 </div>
355 <div class="bws_pro_links">
356 <a class="bws_button" href="http://bestwebsoft.com/products/pdf-print/buy/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="PDF & Print Pro">
357 <?php _e( 'Go', 'pdf-print' ); ?> <strong>PRO</strong>
358 </a>
359 </div>
360 <div class="clear"></div>
361 </div>
362 </div>
363 <input type="hidden" name="pdfprnt_form_submit" value="1" />
364 <p class="submit">
365 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
366 </p>
367 <?php wp_nonce_field( $plugin_basename, 'pdfprnt_nonce_name' ); ?>
368 </form>
369 <?php bws_plugin_reviews_block( $pdfprnt_plugin_info['Name'], 'pdf-print' ); ?>
370 <?php } elseif ( 'extra' == $_GET['action'] ) { ?>
371 <div class="bws_pro_version_bloc">
372 <div class="bws_pro_version_table_bloc">
373 <div class="bws_table_bg"></div>
374 <table class="form-table bws_pro_version">
375 <tr valign="top">
376 <td colspan="2">
377 <?php _e( 'Please choose the necessary post types (or single pages), where PDF & Print buttons should be displayed:', 'pdf-print' ); ?>
378 </td>
379 </tr>
380 <tr valign="top">
381 <td colspan="2">
382 <label>
383 <input disabled="disabled" checked="checked" id="twttrpr_jstree_url" type="checkbox" name="twttrpr_jstree_url" value="1" />
384 <?php _e( "Show URL for pages", 'pdf-print' );?>
385 </label>
386 </td>
387 </tr>
388 <tr valign="top">
389 <td colspan="2">
390 <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' ); ?>" />
391 </td>
392 </tr>
393 <tr valign="top">
394 <td colspan="2">
395 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
396 </td>
397 </tr>
398 <tr valign="top">
399 <th scope="row" colspan="2">
400 * <?php _e( 'If you upgrade to Pro version all your settings will be saved.', 'pdf-print' ); ?>
401 </th>
402 </tr>
403 </table>
404 </div>
405 <div class="bws_pro_version_tooltip">
406 <div class="bws_info">
407 <?php _e( 'Unlock premium options by upgrading to a PRO version.', 'pdf-print' ); ?>
408 <a 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>
409 </div>
410 <a class="bws_button" href="http://bestwebsoft.com/products/pdf-print/buy/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="PDF & Print Pro">
411 <?php _e( 'Go', 'pdf-print' ); ?> <strong>PRO</strong>
412 </a>
413 <div class="clear"></div>
414 </div>
415 </div>
416 <?php bws_plugin_reviews_block( $pdfprnt_plugin_info['Name'], 'pdf-print' ); ?>
417 <?php } elseif ( 'go_pro' == $_GET['action'] ) {
418 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'] ) );
419 } ?>
420 </div>
421 <?php }
422 }
423
424 /* Positioning buttons in the page */
425 if( ! function_exists( 'pdfprnt_content' ) ) {
426 function pdfprnt_content( $content ) {
427 if ( is_admin() )
428 return;
429 global $pdfprnt_options_array, $post;
430 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.
431 return $content;
432 if ( 1 == $pdfprnt_options_array['show_btn_pdf'] || 1 == $pdfprnt_options_array['show_btn_print'] ) {
433 $position = ( 'top-left' == $pdfprnt_options_array['position'] || 'top-right' == $pdfprnt_options_array['position'] ) ? true : false;
434 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position'] . '">';
435 if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) {
436 if ( ! is_front_page () )
437 $permalink = add_query_arg( 'print' , 'pdf' , get_permalink( $post->ID ) );
438 else
439 $permalink = add_query_arg( 'print' , 'pdf' , get_permalink() . '?page_id=' . $post->ID );
440 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="View PDF" /></a>';
441 }
442 if ( 1 == $pdfprnt_options_array['show_btn_print'] ) {
443 if ( ! is_front_page () )
444 $permalink = add_query_arg( 'print' , 'print' , get_permalink( $post->ID ) );
445 else
446 $permalink = add_query_arg( 'print' , 'print' , get_permalink() . '?page_id=' . $post->ID );
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 if ( $position )
451 $content = $str . $content;
452 else
453 $content = $content . $str;
454 unset( $position );
455 unset( $str );
456 }
457 return $content;
458 }
459 }
460
461 /* Output buttons for search or archive pages */
462 if( ! function_exists( 'pdfprnt_show_buttons_search_archive' ) ) {
463 function pdfprnt_show_buttons_search_archive() {
464 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp, $posts;
465 if ( 0 < $pdfprnt_output_count_buttons ||
466 ( ! ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] || 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) )
467 )
468 return;
469 /* Check for existence the type of posts. */
470 $is_return = true;
471 foreach ( $posts as $post ) {
472 if ( in_array( $post->post_type, $pdfprnt_options_array['use_types_posts'] ) ) {
473 $is_return = false;
474 break;
475 }
476 }
477 if ( $is_return )
478 return;
479 $pdfprnt_output_count_buttons ++;
480 if ( empty( $wp->request ) )
481 $current_url = add_query_arg( $wp->query_string, '', home_url() );
482 else
483 $current_url = home_url( $wp->request );
484 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position_search_archive'] . '">';
485 if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) {
486 $permalink = add_query_arg( 'print' , 'pdf-page' , $current_url );
487 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
488 }
489 if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) {
490 $permalink = add_query_arg( 'print' , 'print-page' , $current_url );
491 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
492 }
493 $str .= '</div>';
494 unset( $current_url );
495 unset( $permalink );
496 echo $str;
497 }
498 }
499 /**
500 * Display buttons only with main loop
501 * @param array $content list with data of posts, which needs to displaing in the loop
502 * @return void
503 */
504 if ( ! function_exists( 'pdfprnt_display_with_loop' ) ) {
505 function pdfprnt_display_with_loop( $content ) {
506 global $wp_query;
507 if ( is_main_query() && $content === $wp_query ) { /* make sure that we display pdf/print buttons only with main loop */
508 pdfprnt_show_buttons_search_archive();
509 }
510 }
511 }
512
513 if ( ! function_exists( 'pdfprnt_auto_show_buttons_search_archive' ) ) {
514 function pdfprnt_auto_show_buttons_search_archive() {
515 if ( is_search() || is_archive() || is_category() || is_tax() || is_tag() || is_author() ) {
516 global $pdfprnt_options_array;
517 if ( in_array( $pdfprnt_options_array['position_search_archive'], array( 'top-left', 'top-right' ) ) )
518 add_action( 'loop_start', 'pdfprnt_display_with_loop' );
519 else
520 add_action( 'loop_end', 'pdfprnt_display_with_loop' );
521 }
522 }
523 }
524
525 /* Output buttons of page for BWS Portfolio plugin */
526 if( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio' ) ) {
527 function pdfprnt_show_buttons_for_bws_portfolio() {
528 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp;
529 if (
530 0 < $pdfprnt_output_count_buttons ||
531 (
532 ! ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] || 1 == $pdfprnt_options_array['show_btn_print_custom'] ) &&
533 in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] )
534 )
535 )
536 return;
537 $pdfprnt_output_count_buttons++;
538 if ( empty( $wp->request ) )
539 $current_url = add_query_arg( $wp->query_string, '', home_url() );
540 else
541 $current_url = home_url( $wp->request );
542 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position_custom'] . '">';
543 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
544 $permalink = add_query_arg( 'print' , 'pdf-portfolio-page' , $current_url );
545 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
546 }
547 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
548 $permalink = add_query_arg( 'print' , 'print-portfolio-page' , $current_url );
549 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
550 }
551 $str .= '</div>';
552 unset( $current_url );
553 unset( $permalink );
554 return $str;
555 }
556 }
557
558 /* Output buttons of post for BWS Portfolio plugin */
559 if ( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio_post' ) ) {
560 function pdfprnt_show_buttons_for_bws_portfolio_post() {
561 global $pdfprnt_options_array;
562 if (
563 ! ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] || 1 == $pdfprnt_options_array['show_btn_print_custom'] ) &&
564 in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] )
565 )
566 return;
567 $current_url = get_permalink();
568 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position_custom'] . '">';
569 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
570 $permalink = add_query_arg( 'print' , 'pdf-portfolio' , $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_custom'] ) {
574 $permalink = add_query_arg( 'print' , 'print-portfolio' , $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 unset( $current_url );
579 unset( $permalink );
580 return $str;
581 }
582 }
583
584 /* Output buttons of page for custom post type */
585 if ( ! function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) {
586 function pdfprnt_show_buttons_for_custom_post_type( $user_query = '' ) {
587 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $post, $wp, $posts;
588 if (
589 0 < $pdfprnt_output_count_buttons ||
590 ( ! ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] || 1 == $pdfprnt_options_array['show_btn_print_custom'] ) ) ||
591 ( ! ( is_array( $user_query ) || is_string( $user_query ) ) )
592 )
593 return;
594 $is_return = true;
595 if ( empty( $user_query ) ) { /* set necessary values of parameters for pdf/print buttons */
596 $current_url = empty( $wp->request ) ? add_query_arg( $wp->query_string, '', home_url() ) : home_url( $wp->request );
597 $nothing_else = false;
598 if ( is_search() || is_archive() || is_category() || is_tax() || is_tag() || is_author() ) { /* search, cattegories, archives */
599 foreach ( $posts as $value ) {
600 if ( in_array( $value->post_type, $pdfprnt_options_array['use_types_posts'] ) ) {
601 $is_return = false;
602 break;
603 }
604 }
605 if ( $is_return )
606 return;
607 $pdf_query_parameter = 'pdf-page';
608 $print_query_parameter = 'print-page';
609 } elseif ( is_page() ) { /* pages */
610 $page_template = get_post_meta( $post->ID, '_wp_page_template');
611 if ( in_array( $page_template[0], array( 'portfolio.php', 'portfolio-pro.php' ) ) ) {
612 if ( in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] ) ) {
613 $pdf_query_parameter = 'pdf-portfolio-page';
614 $print_query_parameter = 'print-portfolio-page';
615 } else {
616 return;
617 }
618 } else {
619 $nothing_else = true;
620 }
621 } elseif ( is_single() ) { /* posts */
622 $post_type = get_post_type( $post->ID );
623 if ( 'portfolio' == $post_type ) {
624 if ( in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] ) ) {
625 $pdf_query_parameter = 'pdf-portfolio';
626 $print_query_parameter = 'print-portfolio';
627 } else {
628 return;
629 }
630 } else {
631 $nothing_else = true;
632 }
633 } else {
634 $nothing_else = true;
635 }
636 if ( $nothing_else ) {
637 $pdf_query_parameter = 'pdf';
638 $print_query_parameter = 'print';
639 }
640 } else {
641 $custom_query = new WP_Query( $user_query );
642 $current_url = add_query_arg( $custom_query->query, '', home_url() );
643 /* Check for existence the type of posts. */
644 if ( ! empty( $custom_query->posts) ) {
645 foreach ( $custom_query->posts as $post ) {
646 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
647 $is_return = false;
648 break;
649 }
650 }
651 }
652 if ( $is_return )
653 return;
654 $pdf_query_parameter = 'pdf-custom-page';
655 $print_query_parameter = 'print-custom-page';
656 }
657 $pdfprnt_output_count_buttons++;
658 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position_custom'] . '">';
659 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
660 $permalink = add_query_arg( 'print' , $pdf_query_parameter , $current_url );
661 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
662 }
663 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
664 $permalink = add_query_arg( 'print' , $print_query_parameter , $current_url );
665 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
666 }
667 $str .= '</div>';
668 unset( $current_url );
669 unset( $permalink );
670 unset( $is_return );
671 unset( $custom_query );
672 return $str;
673 }
674 }
675
676 /* Add links */
677 if ( ! function_exists( 'pdfprnt_action_links' ) ) {
678 function pdfprnt_action_links( $links, $file ) {
679 if ( ! is_network_admin() ) {
680 $base = plugin_basename( __FILE__ );
681 if ( $file == $base ) {
682 $settings_link = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
683 array_unshift( $links, $settings_link );
684 }
685 }
686 return $links;
687 }
688 }
689
690 /* Add links */
691 if ( ! function_exists( 'pdfprnt_links' ) ) {
692 function pdfprnt_links( $links, $file ) {
693 $base = plugin_basename( __FILE__ );
694 if ( $file == $base ) {
695 if ( ! is_network_admin() )
696 $links[] = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
697 $links[] = '<a href="http://wordpress.org/plugins/pdf-print/faq/" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>';
698 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'pdf-print' ) . '</a>';
699 }
700 return $links;
701 }
702 }
703
704 /* Add stylesheets */
705 if ( ! function_exists ( 'pdfprnt_admin_head' ) ) {
706 function pdfprnt_admin_head() {
707 global $wp_version;
708 if ( $wp_version < 3.8 )
709 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style_wp_before_3.8.css', __FILE__ ) );
710 else
711 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
712
713 if ( isset( $_GET['page'] ) && "pdf-print.php" == $_GET['page'] ) {
714 wp_enqueue_script( 'pdfprnt_script', plugins_url( 'js/script.js', __FILE__ ) );
715 wp_localize_script( 'pdfprnt_script', 'pdfprnt_var', array(
716 'loading_fonts' => __( 'Loading of fonts. It might take a several minutes', 'pdf-print' ),
717 'ajax_nonce' => wp_create_nonce( 'pdfprnt_ajax_nonce' ),
718 )
719 );
720 }
721 }
722 }
723 /* Remove inline 'font-family' and 'font' styles from content */
724 if ( ! function_exists( 'pdfprnt_preg_replace' ) ) {
725 function pdfprnt_preg_replace( $pattern, $content ) {
726 $content = preg_replace( "/" . $pattern . "(.*?);/", "", $content );
727 preg_match_all( "~style=(\"\'?)~", $content, $quotes );/* get array with quotes */
728 if ( isset( $quotes[1] ) && ! empty( $quotes[1] ) ) {
729 foreach ( $quotes[1] as $quote ) {
730 preg_match_all( "~style=" . $quote . "(.*?)" . $quote . "~", $content, $styles );
731 if ( ! empty( $styles[1] ) ) {
732 foreach ( $styles[1] as $style ) {
733 if ( preg_match( "/" . $pattern . "/", $style ) )
734 $content = preg_replace( "/" . $style . "/", "", $content );
735 }
736
737 }
738 }
739 }
740 return $content;
741 }
742 }
743
744 /* Generate templates for pdf file or print */
745 if ( ! function_exists( 'pdfprnt_generate_template' ) ) {
746 function pdfprnt_generate_template( $content, $isprint = false ) {
747 global $pdfprnt_options_array;
748 ob_start(); /* Starting output buffering */ ?>
749 <html>
750 <head>
751 <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) {
752 /* remove 'font-family' and 'font' styles from theme css-file if additional fonts not loaded */
753 if ( 0 == $pdfprnt_options_array['additional_fonts'] ) {
754 $css = file_get_contents( get_bloginfo( 'stylesheet_url' ) );
755 if ( ( ! empty( $css ) ) ) {
756 $css = preg_replace( "/font:(.*?);/", "", $css );
757 $css = preg_replace( "/font-family(.*?);/", "", $css );
758 echo '<style type="text/css">' . $css . '</style>';
759 }
760 } else { ?>
761 <link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo( 'stylesheet_url' ); ?>" media="all" />
762 <?php }
763 } else { ?>
764 <link type="text/css" rel="stylesheet" href="<?php echo plugins_url( 'css/default.css', __FILE__ ); ?>" media="all" />
765 <?php }
766 if ( $isprint && 1 == $pdfprnt_options_array['show_print_window'] ) {
767 echo '<script>window.onload = function(){ window.print(); };</script>';
768 } ?>
769 </head>
770 <body>
771 <?php if ( 0 == $pdfprnt_options_array['additional_fonts'] ) {
772 /* Remove inline 'font-family' and 'font' styles from content */
773 $content = pdfprnt_preg_replace( "font-family", $content );
774 $content = pdfprnt_preg_replace( "font:", $content );
775 }
776 echo $content; ?>
777 </body>
778 </html>
779 <?php $html = ob_get_contents(); /* Getting output buffering */
780 ob_end_clean(); /* Closing output buffering */
781 return $html; /* Now we done with template */
782 }
783 }
784
785 if ( ! function_exists( 'pdfprnt_generate_template_for_bws_portfolio' ) ) {
786 function pdfprnt_generate_template_for_bws_portfolio() {
787 global $post;
788 ob_start(); /* Starting output buffering */
789 $short_descr = $link = $date_compl = '';
790 $meta_values = get_post_custom( $post->ID );
791 $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
792 if ( empty ( $post_thumbnail_id ) ) {
793 $args = array(
794 'post_parent' => $post->ID,
795 'post_type' => 'attachment',
796 'post_mime_type' => 'image',
797 'numberposts' => 1
798 );
799 $attachments = get_children( $args );
800 $post_thumbnail_id = key( $attachments );
801 }
802 $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
803 $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
804 $image_desc = get_post( $post_thumbnail_id );
805 $image_desc = $image_desc->post_content;
806 $post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
807 if ( ! empty( $post_meta ) ) {
808 $date_compl = $post_meta['_prtfl_date_compl'];
809 if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
810 $date_compl = explode( '/', $date_compl );
811 $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1] . '-' . $date_compl[0] . '-' . $date_compl[2] ) );
812 }
813 $link = $post_meta['_prtfl_link'];
814 $short_descr = $post_meta['_prtfl_short_descr'];
815 }
816 if ( ! empty( $image[1] ) ) { ?>
817 <img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" alt="<?php echo $image_alt; ?>" />
818 <?php } ?>
819 <div>
820 <p>
821 <strong><?php _e( 'Date of completion', 'pdf-print' ); ?>:</strong> <?php echo $date_compl; ?><br/>
822 <strong><?php _e( 'Link', 'pdf-print' ); ?>:</strong> <a href="<?php echo $link; ?>"><?php echo $link; ?></a><br/>
823 <strong><?php _e( 'Description', 'pdf-print' ); ?>:</strong> <?php echo $short_descr; ?><br/>
824 </p>
825 </div>
826 <?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
827 if ( is_array( $terms ) && count( $terms ) > 0 ) { ?>
828 <div style="clear:both;">
829 <strong><?php _e( 'Technologies', 'pdf-print' ); ?>: </strong>
830 <?php $count = 0;
831 foreach ( $terms as $term ) {
832 if ( 0 < $count )
833 echo ', ';
834 echo '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
835 $count++;
836 } ?>
837 </div>
838 <?php }
839 $content = ob_get_contents(); /* Getting output buffering */
840 ob_end_clean(); /* Closing output buffering */
841 return $content; /* Now we done with template */
842 }
843 }
844
845 /* Generate query posts for Portfolio plugin */
846 if ( ! function_exists( 'generate_query_posts_for_portfolio' ) ) {
847 function generate_query_posts_for_portfolio() {
848 global $wp_query;
849 $paged = isset( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 1;
850 $technologies = isset( $wp_query->query_vars["technologies"] ) ? $wp_query->query_vars["technologies"] : "";
851 if ( "" != $technologies ) {
852 $args = array(
853 'post_type' => 'portfolio',
854 'post_status' => 'publish',
855 'posts_per_page' => get_option('posts_per_page'),
856 'paged' => $paged,
857 'tax_query' => array(
858 array(
859 'taxonomy' => 'portfolio_technologies',
860 'field' => 'slug',
861 'terms' => $technologies
862 )
863 )
864 );
865 } else {
866 $args = array(
867 'post_type' => 'portfolio',
868 'post_status' => 'publish',
869 'posts_per_page' => get_option('posts_per_page'),
870 'paged' => $paged
871 );
872 }
873 query_posts( $args );
874 }
875 }
876
877 /* Output print page or pdf document and include plugin script */
878 if ( ! function_exists( 'pdfprnt_print' ) ) {
879 function pdfprnt_print( $query ) {
880 global $pdfprnt_options_array, $posts, $post;
881 if ( $print = get_query_var( 'print' ) ) {
882 remove_all_filters( 'the_content' );
883 add_filter( 'the_content', 'capital_P_dangit', 11 );
884 add_filter( 'the_content', 'wptexturize' );
885 add_filter( 'the_content', 'convert_smilies' );
886 add_filter( 'the_content', 'convert_chars' );
887 add_filter( 'the_content', 'wpautop' );
888 if ( ! 0 == $pdfprnt_options_array['tmpl_shorcode'] ) {
889 add_filter( 'the_content', 'do_shortcode' ); /* executing shortcodes on the page */
890 } else {
891 $pattern = get_shortcode_regex();
892 if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) ) { /* getting all shortcodes we are using */
893 foreach ( array_unique( $matches[0] ) as $value) {
894 $post->post_content = str_replace( $value, "", $post->post_content ); /* replacing shortcodes to an empty string */
895 }
896 }
897 }
898 /* set path to directory with fonts for PDF document */
899 if ( ! ( 0 == $pdfprnt_options_array['additional_fonts'] && defined( "_MPDF_SYSTEM_TTFONTS" ) ) ) {
900 if ( is_multisite() ) {
901 switch_to_blog( 1 );
902 $upload_dir = wp_upload_dir();
903 restore_current_blog();
904 } else {
905 $upload_dir = wp_upload_dir();
906 }
907 define( '_MPDF_SYSTEM_TTFONTS', $upload_dir['basedir'] .'/pdf-print-fonts/' );
908 }
909 switch ( $print ) {
910 case 'pdf': /* Content for PDF from post */
911 include ( 'mpdf/mpdf.php' );
912 $user_info = get_userdata( $post->post_author );
913 $default_font = 0 == $pdfprnt_options_array['additional_fonts'] ? 'dejavusansmono' : '';
914 $mpdf = new mPDF( '+aCJK', 'A4', 0, $default_font );
915 $mpdf->allow_charset_conversion = true;
916 $mpdf->charset_in = get_bloginfo( 'charset' );
917 if ( ! 0 == $pdfprnt_options_array['additional_fonts'] ) {
918 $mpdf->autoScriptToLang = true;
919 $mpdf->autoLangToFont = true;
920 $mpdf->baseScript = 1;
921 $mpdf->autoVietnamese = true;
922 $mpdf->autoArabic = true;
923 }
924 if ( is_rtl() )
925 $mpdf->SetDirectionality( 'rtl' );
926 $mpdf->SetAuthor( $user_info->display_name );
927 $mpdf->SetTitle( $post->post_title );
928 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
929 $html = '<div id="content">
930 <div class="post">
931 <div class="entry-header"><h1 class="entry-title"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
932 <div class="entry-content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
933 </div>
934 </div>';
935 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
936 $mpdf->Output();
937 unset( $user_info );
938 unset( $html );
939 unset( $mpdf );
940 die();
941 break;
942 case 'print': /* Content for printing from post */
943 $html = '<div id="content">
944 <div class="post">
945 <div class="entry-header"><h1 class="entry-title">' . $post->post_title . '</h1></div><br/>
946 <div class="entry-content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
947 </div>
948 </div>';
949 echo pdfprnt_generate_template( $html, true );
950 unset( $html );
951 die();
952 break;
953 case 'pdf-page': /* Content for PDF from archive or searching page */
954 $titles = array();
955 $authors = array();
956 include ( 'mpdf/mpdf.php' );
957 $user_info = get_userdata( $post->post_author );
958 $default_font = 0 == $pdfprnt_options_array['additional_fonts'] ? 'dejavusansmono' : '';
959 $mpdf = new mPDF( '+aCJK', 'A4', 0, $default_font );
960 $mpdf->allow_charset_conversion = true;
961 $mpdf->charset_in = get_bloginfo( 'charset' );
962 if ( ! 0 == $pdfprnt_options_array['additional_fonts'] ) {
963 $mpdf->autoScriptToLang = true;
964 $mpdf->autoLangToFont = true;
965 $mpdf->baseScript = 1;
966 $mpdf->autoVietnamese = true;
967 $mpdf->autoArabic = true;
968 }
969 if ( is_rtl() )
970 $mpdf->SetDirectionality( 'rtl' );
971 $html = '<div id="content">';
972 foreach ( $posts as $p ) {
973 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
974 continue;
975 $titles[] = $p->post_title;
976 $user_info = get_userdata( $p->post_author );
977 $authors[] = $user_info->display_name;
978 $html .= '<div class="post">
979 <div class="entry-title"><h1 class="entry-header"><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>
980 <div class="entry-content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
981 </div><br/><hr/><br/>';
982 unset( $user_info );
983 }
984 $html .= '</div>';
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 unset( $authors );
993 unset( $titles );
994 unset( $html );
995 unset( $mpdf );
996 die();
997 break;
998 case 'print-page': /* Content for printing from archive or searching page */
999 $html = '<div id="content">';
1000 foreach ( $posts as $p ) {
1001 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1002 continue;
1003 $html .= '<div class="post">
1004 <div class="entry-header"><h1 class="entry-title">' . $p->post_title . '</h1></div><br/>
1005 <div class="entry-content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
1006 </div><br/><hr/><br/>';
1007 }
1008 $html .= '</div>';
1009 echo pdfprnt_generate_template( $html, true );
1010 unset( $html );
1011 die();
1012 break;
1013 case 'pdf-portfolio': /* Content for PDF from portfolio post */
1014 include ( 'mpdf/mpdf.php' );
1015 $user_info = get_userdata( $post->post_author );
1016 $default_font = 0 == $pdfprnt_options_array['additional_fonts'] ? 'dejavusansmono' : '';
1017 $mpdf = new mPDF( '+aCJK', 'A4', 0, $default_font );
1018 $mpdf->allow_charset_conversion = true;
1019 $mpdf->charset_in = get_bloginfo( 'charset' );
1020 if ( ! 0 == $pdfprnt_options_array['additional_fonts'] ) {
1021 $mpdf->autoScriptToLang = true;
1022 $mpdf->autoLangToFont = true;
1023 $mpdf->baseScript = 1;
1024 $mpdf->autoVietnamese = true;
1025 $mpdf->autoArabic = true;
1026 }
1027 if ( is_rtl() )
1028 $mpdf->SetDirectionality( 'rtl' );
1029 $mpdf->SetAuthor( $user_info->display_name );
1030 $mpdf->SetTitle( $post->post_title );
1031 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1032 $html = '<div id="content">
1033 <div class="post">
1034 <div class="entry-header"><h1 class="entry-title"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
1035 <div class="entry-content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1036 </div>
1037 </div>';
1038 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
1039 $mpdf->Output();
1040 unset( $html );
1041 unset( $user_info );
1042 unset( $mpdf );
1043 die();
1044 break;
1045 case 'print-portfolio': /* Content for printing from porfolio post */
1046 $html = '<div id="content">
1047 <div class="post">
1048 <div class="entry-header"><h1 class="entry-title">' . $post->post_title . '</h1></div><br/>
1049 <div class="entry-content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1050 </div>
1051 </div>';
1052 echo pdfprnt_generate_template( $html, true );
1053 unset( $html );
1054 die();
1055 break;
1056 case 'pdf-portfolio-page': /* Content for PDF from portfolio page */
1057 $html = '<div id="content">';
1058 $titles = array();
1059 $authors = array();
1060 generate_query_posts_for_portfolio();
1061 while ( have_posts() ) {
1062 the_post();
1063 global $post;
1064 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
1065 continue;
1066 $titles[] = $post->post_title;
1067 $user_info = get_userdata( $post->post_author );
1068 $authors[] = $user_info->display_name;
1069 $html .= '<div class="post">
1070 <div class="entry-header"><h1 class="entry-title"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
1071 <div class="entry-content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1072 </div><br/><hr/><br/>';
1073 unset( $user_info );
1074 }
1075 $html .= '</div>';
1076 include ( 'mpdf/mpdf.php' );
1077 $default_font = 0 == $pdfprnt_options_array['additional_fonts'] ? 'dejavusansmono' : '';
1078 $mpdf = new mPDF( '+aCJK', 'A4', 0, $default_font );
1079 $mpdf->allow_charset_conversion = true;
1080 $mpdf->charset_in = get_bloginfo( 'charset' );
1081 if ( ! 0 == $pdfprnt_options_array['additional_fonts'] ) {
1082 $mpdf->autoScriptToLang = true;
1083 $mpdf->autoLangToFont = true;
1084 $mpdf->baseScript = 1;
1085 $mpdf->autoVietnamese = true;
1086 $mpdf->autoArabic = true;
1087 }
1088 if ( is_rtl() )
1089 $mpdf->SetDirectionality( 'rtl' );
1090 $titles = array_unique( $titles );
1091 $authors = array_unique( $authors );
1092 $mpdf->SetTitle( implode( ',', $titles ) );
1093 $mpdf->SetAuthor( implode( ',', $authors ) );
1094 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1095 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
1096 $mpdf->Output();
1097 unset( $authors );
1098 unset( $titles );
1099 unset( $html );
1100 unset( $mpdf );
1101 die();
1102 break;
1103 case 'print-portfolio-page': /* Content for printing from portfolio page */
1104 generate_query_posts_for_portfolio();
1105 $html = '<div id="content">';
1106 while ( have_posts() ) {
1107 the_post();
1108 global $post;
1109 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
1110 continue;
1111 $html .= '<div class="post">
1112 <div class="entry-header"><h1 class="entry-title">' . $post->post_title . '</h1></div><br/>
1113 <div class="entry-content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1114 </div><br/><hr/><br/>';
1115 }
1116 $html .= '</div>';
1117 echo pdfprnt_generate_template( $html, true );
1118 unset( $html );
1119 die();
1120 break;
1121 case 'pdf-custom-page': /* Content for PDF from custom post */
1122 $html = '<div id="content">';
1123 $titles = $authors = array();
1124
1125 foreach ( $posts as $p ) {
1126 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1127 continue;
1128 $titles[] = $p->post_title;
1129 $user_info = get_userdata( $p->post_author );
1130 $authors[] = $user_info->display_name;
1131 $html .= '<div class="post">
1132 <div class="entry-header"><h1 class="entry-title"><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>
1133 <div class="entry-content">';
1134 /*if ( has_post_thumbnail( $p->ID ) )
1135 $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );*/
1136 $html .= apply_filters( 'the_content', $p->post_content ) . '</div></div><br/><hr/><br/>';
1137 unset( $user_info );
1138 }
1139 $html .= '</div>';
1140 include ( 'mpdf/mpdf.php' );
1141 $default_font = 0 == $pdfprnt_options_array['additional_fonts'] ? 'dejavusansmono' : '';
1142 $mpdf = new mPDF( '+aCJK', 'A4', 0, $default_font );
1143 $mpdf->allow_charset_conversion = true;
1144 $mpdf->charset_in = get_bloginfo( 'charset' );
1145 if ( ! 0 == $pdfprnt_options_array['additional_fonts'] ) {
1146 $mpdf->autoScriptToLang = true;
1147 $mpdf->autoLangToFont = true;
1148 $mpdf->baseScript = 1;
1149 $mpdf->autoVietnamese = true;
1150 $mpdf->autoArabic = true;
1151 }
1152 if ( is_rtl() )
1153 $mpdf->SetDirectionality( 'rtl' );
1154 $titles = array_unique( $titles );
1155 $authors = array_unique( $authors );
1156 $mpdf->SetTitle( implode( ',', $titles ) );
1157 $mpdf->SetAuthor( implode( ',', $authors ) );
1158 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1159 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
1160 $mpdf->Output();
1161 unset( $authors );
1162 unset( $titles );
1163 unset( $html );
1164 unset( $mpdf );
1165 die();
1166 break;
1167 case 'print-custom-page': /* Content for printing from custom post */
1168 $html = '<div id="content">';
1169 foreach ( $posts as $p ) {
1170 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1171 continue;
1172 $html .= '<div class="post">
1173 <div class="entry-header"><h1 class="entry-title">' . $p->post_title . '</h1></div><br/>
1174 <div class="entry-content">';
1175 /*if ( has_post_thumbnail( $p->ID ) )
1176 $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );*/
1177 $html .= apply_filters( 'the_content', $p->post_content ) . '</div></div><br/><hr/><br/>';
1178 }
1179 $html .= '</div>';
1180 echo pdfprnt_generate_template( $html, true );
1181 unset( $html );
1182 die();
1183 break;
1184 }
1185 }
1186 }
1187 }
1188
1189 /* Add query vars */
1190 if ( ! function_exists( 'print_vars_callback' ) ) {
1191 function print_vars_callback( $query_vars ) {
1192 $query_vars[] = 'print';
1193 return $query_vars;
1194 }
1195 }
1196
1197 /**
1198 * Class Pdfprnt_ZipArchive for extracting
1199 * necessary folder from zip-archive
1200 */
1201 if ( class_exists( 'ZipArchive' ) && ! class_exists( 'Pdfprnt_ZipArchive' ) ) {
1202 class Pdfprnt_ZipArchive extends ZipArchive {
1203 /**
1204 * constructor of class
1205 */
1206 public function extractSubdirTo( $destination, $subdir ) {
1207 $errors = array();
1208 $charset = get_bloginfo( 'charset' );
1209 // Prepare dirs
1210 $destination = str_replace( array("/", "\\"), DIRECTORY_SEPARATOR, $destination );
1211 $subdir = str_replace( array("/", "\\"), "/", $subdir);
1212
1213 if ( substr( $destination, mb_strlen( DIRECTORY_SEPARATOR, $charset ) * -1 ) != DIRECTORY_SEPARATOR )
1214 $destination .= DIRECTORY_SEPARATOR;
1215
1216 if ( substr( $subdir, -1 ) != "/" )
1217 $subdir .= "/";
1218 // Extract files
1219 for ( $i = 0; $i < $this->numFiles; $i++ ) {
1220 $filename = $this->getNameIndex( $i );
1221
1222 if ( substr( $filename, 0, mb_strlen( $subdir, $charset ) ) == $subdir ) {
1223 $relativePath = substr( $filename, mb_strlen( $subdir, $charset ) );
1224 $relativePath = str_replace( array( "/", "\\" ), DIRECTORY_SEPARATOR, $relativePath );
1225
1226 if ( mb_strlen( $relativePath, $charset ) > 0 ) {
1227 if ( substr( $filename, -1 ) == "/" ) {
1228 if ( ! is_dir( $destination . $relativePath ) )
1229 if ( ! @mkdir( $destination . $relativePath, 0755, true ) )
1230 $errors[$i] = $filename;
1231 } else {
1232 if ( dirname( $relativePath) != "." ) {
1233 if ( ! is_dir( $destination . dirname( $relativePath ) ) ) {
1234 // New dir (for file)
1235 @mkdir( $destination . dirname( $relativePath ), 0755, true );
1236 }
1237 }
1238 // New file
1239 if ( @file_put_contents( $destination . $relativePath, $this->getFromIndex( $i ) ) === false )
1240 $errors[$i] = $filename;
1241 }
1242 }
1243 }
1244 }
1245 return $errors;
1246 }
1247 }
1248 }
1249
1250 /**
1251 * Download Zip
1252 */
1253 if ( ! function_exists( 'pdfprnt_download_zip' ) ) {
1254 function pdfprnt_download_zip( $zip_file, $upload_dir ) {
1255 /* check permissions */
1256 if ( is_writable( $upload_dir ) ) {
1257 /* load ZIP-archive */
1258 $result = array();
1259 $fp = fopen( $zip_file, 'w+');
1260 $curl = curl_init();
1261 $curl_parametres = array(
1262 CURLOPT_URL => 'http://mpdf1.com/repos/MPDF60.zip',
1263 CURLOPT_FILE => $fp,
1264 CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"
1265 );
1266 curl_setopt_array( $curl, $curl_parametres );
1267 if ( curl_exec( $curl ) ) {
1268 $result['done'] = 'ok';
1269 } else {
1270 $result['error'] = curl_error( $curl ) . '<br />' . __( 'Check your internet connection', 'pdf-print' );
1271 }
1272 curl_close( $curl );
1273 fclose( $fp );
1274 } else {
1275 $result['error'] = __( 'Cannot load files in to "uploads" folder. Check your permissions', 'pdf-print' );
1276 }
1277 return $result;
1278 }
1279 }
1280
1281 /**
1282 * Copy neccesary fonts to mpdf/ttfonts
1283 * @param string $zip_file path to zip archive
1284 */
1285 if ( ! function_exists( 'pdfprnt_copy_fonts' ) ) {
1286 function pdfprnt_copy_fonts( $zip_file, $upload_dir ) {
1287 global $pdfprnt_options_array;
1288 if ( empty( $pdfprnt_options_array ) )
1289 $pdfprnt_options_array = get_option( 'pdfprnt_options_array' );
1290 if ( is_multisite() )
1291 $network_options = get_site_option( 'pdfprnt_options_array' );
1292 $destination = $upload_dir .'/pdf-print-fonts';
1293 if ( ! file_exists( $destination ) ) {
1294 mkdir( $destination, 0755, true );
1295 }
1296 $result = array();
1297 /* check permissions */
1298 if ( is_writable( $destination ) ) {
1299 $zip = new Pdfprnt_ZipArchive();
1300 /* open zip-archive */
1301 if ( true === $zip->open( $zip_file ) ) {
1302 /* extract folder with fonts */
1303 $errors = $zip->extractSubdirTo( $destination, "mpdf60/ttfonts" );
1304 $zip->close();
1305 /* delete zip-archive */
1306 unlink( $zip_file );
1307 if ( empty( $errors ) ) {
1308 $result['done'] = __( 'Additional fonts were successfully loaded', 'pdf-print' );
1309 $pdfprnt_options_array['additional_fonts'] = count( scandir( $destination ) );
1310 update_option( 'pdfprnt_options_array', $pdfprnt_options_array );
1311 if ( is_multisite() ) {
1312 $network_options['additional_fonts'] = $pdfprnt_options_array['additional_fonts'];
1313 update_site_option( 'pdfprnt_options_array', $network_options );
1314 }
1315 } else {
1316 $result['error'] = __( 'Some errors occur during loading files', 'pdf-print' );
1317 }
1318 } else {
1319 $result['error'] = __( 'Some errors occur during loading files', 'pdf-print' );
1320 }
1321 } else {
1322 $result['error'] = __( 'Cannot create "uploads/pdf-print-fonts" folder. Check your permissions', 'pdf-print' );
1323 }
1324 return $result;
1325 }
1326 }
1327
1328 /**
1329 * Download ZIP-archive with MPDF library,
1330 * copy fonts to folder 'pdf-print-fons'
1331 */
1332 if ( ! function_exists( 'pdfprnt_load_and_copy' ) ) {
1333 function pdfprnt_load_and_copy( $zip_file, $upload_dir ) {
1334 if ( file_exists( $zip_file ) )
1335 unlink( $zip_file );
1336 /* load ZIP-archive */
1337 $result = pdfprnt_download_zip( $zip_file, $upload_dir );
1338 /* if ZIP-archive was download successfully */
1339 if ( isset( $result['done'] ) )
1340 $result = pdfprnt_copy_fonts( $zip_file, $upload_dir );
1341 return $result;
1342 }
1343 }
1344 /**
1345 * Function to load fonts for MPDF library
1346 */
1347 if ( ! function_exists( 'pdfprnt_load_fonts' ) ) {
1348 function pdfprnt_load_fonts() {
1349 global $pdfprnt_options_array;
1350 if ( empty( $pdfprnt_options_array ) )
1351 $pdfprnt_options_array = get_option( 'pdfprnt_options_array' );
1352 $ajax_request = isset( $_REQUEST['action'] ) && 'pdfprnt_load_fonts' == $_REQUEST['action'] ? true : false;
1353 $php_request = isset( $_REQUEST['pdfprnt_action'] ) && 'pdfprnt_load_fonts' == $_REQUEST['pdfprnt_action'] ? true : false;
1354 $verified = isset( $_REQUEST['pdfprnt_ajax_nonce'] ) && wp_verify_nonce( $_REQUEST['pdfprnt_ajax_nonce'], 'pdfprnt_ajax_nonce' ) ? true : false;
1355 if ( ( $ajax_request || $php_request ) && $verified ) {
1356 $result = array();
1357 $flag = false;
1358 /* get path to directory for ZIP-archive uploading */
1359 if ( is_multisite() ) {
1360 switch_to_blog( 1 );
1361 $upload_dir = wp_upload_dir();
1362 restore_current_blog();
1363 } else {
1364 $upload_dir = wp_upload_dir();
1365 }
1366 $zip_file = $upload_dir['basedir'] . '/MPDF60.zip';
1367 $destination = $upload_dir['basedir'] .'/pdf-print-fonts';
1368 if ( file_exists( $destination ) ) { /* if folder with fonts already exists */
1369 if ( is_multisite() ) {
1370 $network_options = get_site_option( 'pdfprnt_options_array' ); /* get network options */
1371 if ( $network_options['additional_fonts'] == count( scandir( $destination ) ) ) { /* if all fonts was loaded successfully */
1372 $pdfprnt_options_array['additional_fonts'] = $network_options['additional_fonts'];
1373 update_option( 'pdfprnt_options_array', $pdfprnt_options_array ); /* update only option of current blog */
1374 $result['done'] = __( 'Additional fonts was successfully loaded', 'pdf-print' );
1375 } else { /* if something wrong */
1376 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'] ); /* load fonts */
1377 }
1378 } else {
1379 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'] ); /* load fonts */
1380 }
1381 } else {
1382 mkdir( $destination, 0755, true );
1383 $result = pdfprnt_load_and_copy( $zip_file, $upload_dir['basedir'] );
1384 }
1385 if ( $ajax_request )
1386 echo json_encode( $result );
1387 else
1388 return $result;
1389 }
1390 if ( $ajax_request )
1391 die();
1392 }
1393 }
1394
1395 if ( ! function_exists ( 'pdfprnt_plugin_banner' ) ) {
1396 function pdfprnt_plugin_banner() {
1397 global $hook_suffix, $pdfprnt_plugin_info;
1398 if ( 'plugins.php' == $hook_suffix ) {
1399 bws_plugin_banner( $pdfprnt_plugin_info, 'pdfprnt', 'pdf-print', 'e2f2549f4d70bc4cb9b48071169d264e', '101', '//ps.w.org/pdf-print/assets/icon-128x128.png' );
1400 }
1401 }
1402 }
1403
1404 /* Deleting plugin options on uninstalling */
1405 if ( ! function_exists( 'pdfprnt_uninstall' ) ) {
1406 function pdfprnt_uninstall() {
1407 delete_option( 'pdfprnt_options_array' );
1408 }
1409 }
1410
1411 /* Adding function to output PDF document or pirnt page */
1412 add_action( 'wp', 'pdfprnt_print' );
1413 add_action( 'wp_head', 'pdfprnt_auto_show_buttons_search_archive' );
1414 /* Initialization */
1415 add_action( 'init', 'pdfprnt_init' );
1416 add_action( 'admin_init', 'pdfprnt_admin_init' );
1417 /* Adding stylesheets */
1418 add_action( 'admin_enqueue_scripts', 'pdfprnt_admin_head' );
1419 add_action( 'wp_enqueue_scripts', 'pdfprnt_admin_head' );
1420 /* Adding 'BWS Plugins' admin menu */
1421 add_action( 'admin_menu', 'pdfprnt_add_pages' );
1422 /* Add query vars */
1423 add_filter( 'query_vars', 'print_vars_callback' );
1424 /* Additional links on the plugin page */
1425 add_filter( 'plugin_action_links', 'pdfprnt_action_links', 10, 2 );
1426 add_filter( 'plugin_row_meta', 'pdfprnt_links', 10, 2 );
1427 /* Adding buttons plugin to content */
1428 add_filter( 'the_content', 'pdfprnt_content' );
1429 /* load additional fonts */
1430 add_action( 'wp_ajax_pdfprnt_load_fonts', 'pdfprnt_load_fonts' );
1431 /* Adding banner */
1432 add_action( 'admin_notices', 'pdfprnt_plugin_banner' );
1433 /* Plugin uninstall function */
1434 register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' );