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

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