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

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

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