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

1,521 lines 72.6 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
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.7.8
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 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_added_menu;
32 $bws_menu_info = get_plugin_data( plugin_dir_path( __FILE__ ) . "bws_menu/bws_menu.php" );
33 $bws_menu_version = $bws_menu_info["Version"];
34 $base = plugin_basename(__FILE__);
35
36 if ( ! isset( $bstwbsftwppdtplgns_options ) ) {
37 if ( is_multisite() ) {
38 if ( ! get_site_option( 'bstwbsftwppdtplgns_options' ) )
39 add_site_option( 'bstwbsftwppdtplgns_options', array(), '', 'yes' );
40 $bstwbsftwppdtplgns_options = get_site_option( 'bstwbsftwppdtplgns_options' );
41 } else {
42 if ( ! get_option( 'bstwbsftwppdtplgns_options' ) )
43 add_option( 'bstwbsftwppdtplgns_options', array(), '', 'yes' );
44 $bstwbsftwppdtplgns_options = get_option( 'bstwbsftwppdtplgns_options' );
45 }
46 }
47
48 if ( isset( $bstwbsftwppdtplgns_options['bws_menu_version'] ) ) {
49 $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version;
50 unset( $bstwbsftwppdtplgns_options['bws_menu_version'] );
51 if ( is_multisite() )
52 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
53 else
54 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
55 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
56 } else if ( ! isset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] ) || $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] < $bws_menu_version ) {
57 $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version;
58 if ( is_multisite() )
59 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
60 else
61 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
62 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
63 } else if ( ! isset( $bstwbsftwppdtplgns_added_menu ) ) {
64 $plugin_with_newer_menu = $base;
65 foreach ( $bstwbsftwppdtplgns_options['bws_menu']['version'] as $key => $value ) {
66 if ( $bws_menu_version < $value && is_plugin_active( $base ) ) {
67 $plugin_with_newer_menu = $key;
68 }
69 }
70 $plugin_with_newer_menu = explode( '/', $plugin_with_newer_menu );
71 $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? basename( WP_CONTENT_DIR ) : 'wp-content';
72 if ( file_exists( ABSPATH . $wp_content_dir . '/plugins/' . $plugin_with_newer_menu[0] . '/bws_menu/bws_menu.php' ) )
73 require_once( ABSPATH . $wp_content_dir . '/plugins/' . $plugin_with_newer_menu[0] . '/bws_menu/bws_menu.php' );
74 else
75 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
76 $bstwbsftwppdtplgns_added_menu = true;
77 }
78
79 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( 'images/px.png', __FILE__ ), 1001 );
80 add_submenu_page( 'bws_plugins', __( 'PDF & Print Settings', 'pdf-print' ), __( 'PDF & Print', 'pdf-print' ), 'manage_options', "pdf-print.php", 'pdfprnt_settings_page' );
81 }
82 }
83
84 /* Init plugin */
85 if ( ! function_exists ( 'pdfprnt_init' ) ) {
86 function pdfprnt_init() {
87 /* Internationalization, first(!) */
88 load_plugin_textdomain( 'pdf-print', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
89 /* Function check if plugin is compatible with current WP version */
90 pdfprnt_version_check();
91 /* Get/Register and check settings for plugin */
92 if ( ! is_admin() || ( isset( $_GET['page'] ) && "pdf-print.php" == $_GET['page'] ) )
93 pdfprnt_settings();
94 }
95 }
96
97 if ( ! function_exists( 'pdfprnt_admin_init' ) ) {
98 function pdfprnt_admin_init() {
99 global $bws_plugin_info, $pdfprnt_plugin_info;
100
101 if ( ! $pdfprnt_plugin_info )
102 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
103
104 if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
105 $bws_plugin_info = array( 'id' => '101', 'version' => $pdfprnt_plugin_info["Version"] );
106 }
107 }
108
109 /* Register settings for plugin */
110 if ( ! function_exists( 'pdfprnt_settings' ) ) {
111 function pdfprnt_settings() {
112 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $pdfprnt_plugin_info;
113
114 if ( ! $pdfprnt_plugin_info ) {
115 if ( ! function_exists( 'get_plugin_data' ) )
116 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
117 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
118 }
119
120 /* Variable to verify performance number of once function. */
121 $pdfprnt_output_count_buttons = 0;
122 $pdfprnt_default_post_types = array();
123 /* Default post types of WordPress. */
124 foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1, '_builtin' => true ), 'names' ) as $value )
125 $pdfprnt_default_post_types[] = $value;
126
127 $pdfprnt_options_array_defaults = array(
128 'plugin_option_version' => $pdfprnt_plugin_info["Version"],
129 'position' => 'top-right',
130 'position_search_archive' => 'left',
131 'position_custom' => 'left',
132 'show_btn_print' => 1,
133 'show_btn_pdf' => 1,
134 'show_btn_print_search_archive' => 1,
135 'show_btn_pdf_search_archive' => 1,
136 'show_btn_print_custom' => 1,
137 'show_btn_pdf_custom' => 1,
138 'use_theme_stylesheet' => 0,
139 'tmpl_post' => 1,
140 'tmpl_search' => 1,
141 'tmpl_custom' => 1,
142 'tmpl_shorcode' => 1,
143 'use_types_posts' => $pdfprnt_default_post_types,
144 'show_print_window' => 0
145 );
146
147 if ( ! get_option( 'pdfprnt_options_array' ) )
148 add_option( 'pdfprnt_options_array', $pdfprnt_options_array_defaults );
149
150 $pdfprnt_options_array = get_option( 'pdfprnt_options_array' );
151
152 if ( ! isset( $pdfprnt_options_array['plugin_option_version'] ) || $pdfprnt_options_array['plugin_option_version'] != $pdfprnt_plugin_info["Version"] ) {
153 $pdfprnt_options_array = array_merge( $pdfprnt_options_array_defaults, $pdfprnt_options_array );
154 $pdfprnt_options_array['plugin_option_version'] = $pdfprnt_plugin_info["Version"];
155 update_option( 'pdfprnt_options_array', $pdfprnt_options_array );
156 }
157 }
158 }
159
160 /* Function check if plugin is compatible with current WP version */
161 if ( ! function_exists ( 'pdfprnt_version_check' ) ) {
162 function pdfprnt_version_check() {
163 global $wp_version, $pdfprnt_plugin_info;
164 $require_wp = "3.0"; /* Wordpress at least requires version */
165 $plugin = plugin_basename( __FILE__ );
166 if ( version_compare( $wp_version, $require_wp, "<" ) ) {
167 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
168 if ( is_plugin_active( $plugin ) ) {
169 deactivate_plugins( $plugin );
170 if ( ! $pdfprnt_plugin_info )
171 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
172 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' );
173 wp_die( "<strong>" . $pdfprnt_plugin_info['Name'] . " </strong> " . __( 'requires', 'pdf-print' ) . " <strong>WordPress" . $require_wp . " </strong> " . __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'pdf-print') . "<br /><br />" . __( 'Back to the WordPress', 'pdf-print') . " <a href='" . $admin_url . "'>" . __( 'Plugins page', 'pdf-print') . "</a>." );
174 }
175 }
176 }
177 }
178
179 /* Add admin page */
180 if ( ! function_exists ( 'pdfprnt_settings_page' ) ) {
181 function pdfprnt_settings_page () {
182 global $pdfprnt_options_array, $wp_version, $pdfprnt_plugin_info, $bstwbsftwppdtplgns_options;
183 $message = $error = "";
184
185 $pdfprnt_positions_values = array(
186 'top-left' => __( 'Top Left', 'pdf-print' ),
187 'top-right' => __( 'Top Right', 'pdf-print' ),
188 'bottom-left' => __( 'Bottom Left', 'pdf-print' ),
189 'bottom-right' => __( 'Bottom Right', 'pdf-print' )
190 );
191
192 if ( ! function_exists( 'get_plugins' ) )
193 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
194 $all_plugins = get_plugins();
195
196 if ( isset( $_REQUEST['pdfprnt_position'] ) &&
197 isset( $_REQUEST['pdfprnt_position_search_archive'] ) &&
198 isset( $_REQUEST['pdfprnt_position_custom'] ) &&
199 isset( $_REQUEST['pdfprnt_use_theme_stylesheet'] ) &&
200 isset( $_REQUEST['pdfprnt_tmpl_post'] ) &&
201 isset( $_REQUEST['pdfprnt_tmpl_custom'] ) &&
202 isset( $_REQUEST['pdfprnt_tmpl_search'] ) &&
203 check_admin_referer( plugin_basename( __FILE__ ), 'pdfprnt_nonce_name' ) ) {
204 $pdfprnt_options_array['position'] = $_REQUEST['pdfprnt_position'];
205 $pdfprnt_options_array['position_search_archive'] = $_REQUEST['pdfprnt_position_search_archive'];
206 $pdfprnt_options_array['position_custom'] = $_REQUEST['pdfprnt_position_custom'];
207 $pdfprnt_options_array['tmpl_post'] = $_REQUEST['pdfprnt_tmpl_post'];
208 $pdfprnt_options_array['tmpl_search'] = $_REQUEST['pdfprnt_tmpl_search'];
209 $pdfprnt_options_array['tmpl_custom'] = $_REQUEST['pdfprnt_tmpl_custom'];
210 $pdfprnt_options_array['use_theme_stylesheet'] = $_REQUEST['pdfprnt_use_theme_stylesheet'];
211 $pdfprnt_options_array['show_btn_pdf'] = isset( $_REQUEST['pdfprnt_show_btn_pdf'] ) ? 1 : 0;
212 $pdfprnt_options_array['show_btn_print'] = isset( $_REQUEST['pdfprnt_show_btn_print'] ) ? 1 : 0;
213 $pdfprnt_options_array['show_btn_pdf_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_search_archive'] ) ? 1 : 0;
214 $pdfprnt_options_array['show_btn_print_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_print_search_archive'] ) ? 1 : 0;
215 $pdfprnt_options_array['show_btn_pdf_custom'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_custom'] ) ? 1 : 0;
216 $pdfprnt_options_array['show_btn_print_custom'] = isset( $_REQUEST['pdfprnt_show_btn_print_custom'] ) ? 1 : 0;
217 $pdfprnt_options_array['tmpl_shorcode'] = isset( $_REQUEST['pdfprnt_tmpl_shorcode'] ) ? 1 : 0;
218 $pdfprnt_options_array['show_print_window'] = isset( $_REQUEST['pdfprnt_show_print_window'] ) ? 1 : 0;
219 $pdfprnt_options_array['use_types_posts'] = isset( $_REQUEST['pdfprnt_use_types_posts'] ) ? $_REQUEST['pdfprnt_use_types_posts'] : array();
220 update_option ( 'pdfprnt_options_array', $pdfprnt_options_array );
221 $message = __( 'Settings saved.', 'pdf-print' );
222 }
223 /* GO PRO */
224 if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
225
226 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? trim( esc_html( $_POST['bws_license_key'] ) ) : "";
227
228 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'bws_license_nonce_name' ) ) {
229 if ( '' != $bws_license_key ) {
230 if ( strlen( $bws_license_key ) != 18 ) {
231 $error = __( "Wrong license key", 'pdf-print' );
232 } else {
233 $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) );
234 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] < ( time() + (24 * 60 * 60) ) ) {
235 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1;
236 } else {
237 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1;
238 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time();
239 }
240
241 /* download Pro */
242 if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) {
243 $current = get_site_transient( 'update_plugins' );
244 if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) {
245 $to_send = array();
246 $to_send["plugins"][ $bws_license_plugin ] = array();
247 $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key;
248 $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true;
249 $options = array(
250 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
251 'body' => array( 'plugins' => serialize( $to_send ) ),
252 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
253 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
254
255 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
256 $error = __( "Something went wrong. Try again later. If the error will appear again, please, contact us <a href=http://support.bestwebsoft.com>BestWebSoft</a>. We are sorry for inconvenience.", 'pdf-print' );
257 } else {
258 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
259
260 if ( is_array( $response ) && !empty( $response ) ) {
261 foreach ( $response as $key => $value ) {
262 if ( "wrong_license_key" == $value->package ) {
263 $error = __( "Wrong license key", 'pdf-print' );
264 } elseif ( "wrong_domain" == $value->package ) {
265 $error = __( "This license key is bind to another site", 'pdf-print' );
266 } elseif ( "you_are_banned" == $value->package ) {
267 $error = __( "Unfortunately, you have exceeded the number of available tries. Please, upload the plugin manually.", 'pdf-print' );
268 }
269 }
270 if ( '' == $error ) {
271 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
272
273 $url = 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/downloads/?bws_first_download=' . $bws_license_plugin . '&bws_license_key=' . $bws_license_key . '&download_from=5';
274 $uploadDir = wp_upload_dir();
275 $zip_name = explode( '/', $bws_license_plugin );
276 $received_content = file_get_contents( $url );
277 if ( ! $received_content ) {
278 $error = __( "Failed to download the zip archive. Please, upload the plugin manually", 'pdf-print' );
279 } else {
280 if ( is_writable( $uploadDir["path"] ) ) {
281 $file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip";
282 if ( file_put_contents( $file_put_contents, $received_content ) ) {
283 @chmod( $file_put_contents, octdec( 755 ) );
284 if ( class_exists( 'ZipArchive' ) ) {
285 $zip = new ZipArchive();
286 if ( $zip->open( $file_put_contents ) === TRUE ) {
287 $zip->extractTo( WP_PLUGIN_DIR );
288 $zip->close();
289 } else {
290 $error = __( "Failed to open the zip archive. Please, upload the plugin manually", 'pdf-print' );
291 }
292 } elseif ( class_exists( 'Phar' ) ) {
293 $phar = new PharData( $file_put_contents );
294 $phar->extractTo( WP_PLUGIN_DIR );
295 } else {
296 $error = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'pdf-print' );
297 }
298 @unlink( $file_put_contents );
299 } else {
300 $error = __( "Failed to download the zip archive. Please, upload the plugin manually", 'pdf-print' );
301 }
302 } else {
303 $error = __( "UploadDir is not writable. Please, upload the plugin manually", 'pdf-print' );
304 }
305 }
306
307 /* activate Pro */
308 if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) {
309 /* activate Pro */
310 $network_wide = false;
311 if ( is_multisite() ) {
312 if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
313 $network_wide = true;
314 }
315 activate_plugin( $bws_license_plugin, NULL, $network_wide );
316 $pro_plugin_is_activated = true;
317 } elseif ( '' == $error ) {
318 $error = __( "Failed to download the zip archive. Please, upload the plugin manually", 'pdf-print' );
319 }
320 }
321 } else {
322 $error = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvienience.", 'pdf-print' );
323 }
324 }
325 }
326 } else {
327 /* activate Pro */
328 $network_wide = false;
329 if ( is_multisite() ) {
330 if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
331 $network_wide = true;
332 }
333 activate_plugin( $bws_license_plugin, NULL, $network_wide );
334 $pro_plugin_is_activated = true;
335 }
336 if ( is_multisite() ) {
337 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
338 } else {
339 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
340 }
341 }
342 } else {
343 $error = __( "Please, enter Your license key", 'pdf-print' );
344 }
345 }
346 } ?>
347 <div class="wrap">
348 <div class="icon32 icon32-bws" id="icon-options-general"></div>
349 <h2><?php _e( 'PDF & Print Settings', 'pdf-print' ); ?></h2>
350 <h2 class="nav-tab-wrapper">
351 <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>
352 <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>
353 <a class="nav-tab" href="http://bestwebsoft.com/products/pdf-print/faq/" target="_blank"><?php _e( 'FAQ', 'pdf-print' ); ?></a>
354 <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>
355 </h2>
356 <div class="updated fade" <?php if ( empty( $message ) || "" != $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
357 <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>
358 <div class="error" <?php if ( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
359 <?php if ( ! isset( $_GET['action'] ) ) { ?>
360 <form method="post" action="admin.php?page=pdf-print.php" id="pdfprnt_settings_form">
361 <table class="form-table pdfprnt_settings_table">
362 <tr>
363 <th scope="row"><?php _e( 'Use of theme stylesheet or plugin default style:', 'pdf-print' ); ?></th>
364 <td>
365 <select name="pdfprnt_use_theme_stylesheet">
366 <option value="0" <?php if ( 0 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Default stylesheet', 'pdf-print' ); ?></option>
367 <option value="1" <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Current theme stylesheet', 'pdf-print' ); ?></option>
368 </select>
369 </td>
370 </tr>
371 <tr>
372 <th scope="row"><?php _e( 'The types of posts that the plugin will use:', 'pdf-print' ); ?></th>
373 <td>
374 <select name="pdfprnt_use_types_posts[]" multiple="multiple">
375 <?php foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1 ), 'objects' ) as $key => $value ) : ?>
376 <option value="<?php echo $key; ?>" <?php if ( in_array( $key, $pdfprnt_options_array['use_types_posts'] ) ) echo 'selected="selected"'; ?>><?php echo $value->label; ?></option>
377 <?php endforeach; ?>
378 </select>
379 </td>
380 </tr>
381 <?php if ( is_plugin_active( 'portfolio/portfolio.php' ) || is_plugin_active( 'portfolio-pro/portfolio-pro.php' ) ) { ?>
382 <tr>
383 <th scope="row"></th>
384 <td>
385 <span class="pdfprnt_explanation"><?php echo __( 'If you are using a Portfolio plugin (powered by bestwebsoft.com) and you need the output pdf and print buttons next to each post, you just need to insert the strings in loop into the template source code in files portfolio.php and portfolio-post.php', 'pdf-print' ) . ' &#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_bws_portfolio_post\' ) ) echo pdfprnt_show_buttons_for_bws_portfolio_post(); ?&#62;<br/> ' . __( ' In order to use PDF and Print buttons for all posts you need to put the strings below into the template source code in file portfolio.php', 'pdf-print' ) . ' &#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_bws_portfolio\' ) ) echo pdfprnt_show_buttons_for_bws_portfolio(); ?&#62;'; ?></span>
386 </td>
387 </tr>
388 <?php } ?>
389 <tr>
390 <th scope="row">
391 <?php _e( 'Position of buttons in content:', 'pdf-print' ); ?>
392 </th>
393 <td>
394 <select name="pdfprnt_position">
395 <?php foreach ( $pdfprnt_positions_values as $key => $value ) : ?>
396 <option value="<?php echo $key; ?>" <?php if ( $pdfprnt_options_array['position'] == $key ) echo 'selected="selected"'; ?>><?php echo $value; ?></option>
397 <?php endforeach; ?>
398 </select>
399 </td>
400 </tr>
401 <tr>
402 <th scope="row"><?php _e( 'Show:', 'pdf-print' ); ?></th>
403 <td>
404 <label><input type="checkbox" name="pdfprnt_show_btn_pdf" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'PDF button', 'pdf-print' ); ?></span></label><br />
405 <label><input type="checkbox" name="pdfprnt_show_btn_print" <?php if ( 1 == $pdfprnt_options_array['show_btn_print'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Print button', 'pdf-print' ); ?></span></label>
406 </td>
407 </tr>
408 <tr>
409 <th scope="row">
410 <?php _e( 'Default template setting for post:', 'pdf-print' ); ?>
411 </th>
412 <td>
413 <div>
414 <label>
415 <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
416 <input type="radio" name="pdfprnt_tmpl_post" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
417 </label>
418 </div>
419 <div>
420 <label>
421 <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
422 <input type="radio" name="pdfprnt_tmpl_post" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
423 </label>
424 </div>
425 <div>
426 <label>
427 <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
428 <input type="radio" name="pdfprnt_tmpl_post" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
429 </label>
430 </div>
431 </td>
432 </tr>
433 <tr>
434 <th scope="row">
435 <?php _e( 'Position of buttons in content for custom post:', 'pdf-print' ); ?>
436 </th>
437 <td>
438 <select name="pdfprnt_position_custom">
439 <option value="pdfprnt-left" <?php if ( 'left' == $pdfprnt_options_array['position_custom'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Left', 'pdf-print' ); ?></option>
440 <option value="pdfprnt-right" <?php if ( 'right' == $pdfprnt_options_array['position_custom'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Right', 'pdf-print' ); ?></option>
441 </select>
442 </td>
443 </tr>
444 <tr>
445 <th scope="row"><?php _e( 'Show for custom posts:', 'pdf-print' ); ?></th>
446 <td>
447 <label><input type="checkbox" name="pdfprnt_show_btn_pdf_custom" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'PDF button', 'pdf-print' ); ?></span></label><br />
448 <label><input type="checkbox" name="pdfprnt_show_btn_print_custom" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Print button', 'pdf-print' ); ?></span></label>
449 </td>
450 </tr>
451 <tr>
452 <th scope="row">
453 <?php _e( 'Default template setting for custom posts:', 'pdf-print' ); ?>
454 </th>
455 <td>
456 <div>
457 <label>
458 <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
459 <input type="radio" name="pdfprnt_tmpl_custom" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
460 </label>
461 </div>
462 <div>
463 <label>
464 <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
465 <input type="radio" name="pdfprnt_tmpl_custom" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
466 </label>
467 </div>
468 <div>
469 <label>
470 <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
471 <input type="radio" name="pdfprnt_tmpl_custom" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
472 </label>
473 </div>
474 </td>
475 </tr>
476 <tr>
477 <th scope="row"></th>
478 <td>
479 <span class="pdfprnt_explanation"><?php echo __( 'In order to use PDF and Print buttons on the custom page you should use the', 'pdf-print' ) . '&#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_custom_post_type\' ) ) echo pdfprnt_show_buttons_for_custom_post_type( $custom_query ); ?&#62;' . ' ' . __( 'where you have to specify query parameters for your custom post.<br/> For example:', 'pdf-print' ) . ' ' . '&#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_custom_post_type\' ) ) echo pdfprnt_show_buttons_for_custom_post_type( \'post_type=gallery&orderby=post_date\' ); ?&#62;' . ' ' . __('or', 'pdf-print') . ' ' . '&#60;?php if ( function_exists( \'pdfprnt_show_buttons_for_custom_post_type\' ) ) echo pdfprnt_show_buttons_for_custom_post_type( array( \'post_type\' => \'gallery\', \'orderby\' => \'post_date\' ) ); ?&#62;.' . ' ' . __( 'For more information on the syntax for assigning parameters to function see <a target="_blank" href="http://codex.wordpress.org/Class_Reference/WP_Query#Parameters">here</a>.', 'pdf-print' ); ?></span>
480 </td>
481 </tr>
482 <tr>
483 <th scope="row">
484 <?php _e( 'Position of buttons on search or archive page:', 'pdf-print' ); ?>
485 </th>
486 <td>
487 <select name="pdfprnt_position_search_archive">
488 <option value="pdfprnt-left" <?php if ( 'left' == $pdfprnt_options_array['position_search_archive'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Left', 'pdf-print' ); ?></option>
489 <option value="pdfprnt-right" <?php if ( 'right' == $pdfprnt_options_array['position_search_archive'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Right', 'pdf-print' ); ?></option>
490 </select>
491 </td>
492 </tr>
493 <tr>
494 <th scope="row"><?php _e( 'Show for search or archive page:', 'pdf-print' ); ?></th>
495 <td>
496 <label><input type="checkbox" name="pdfprnt_show_btn_pdf_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'PDF button', 'pdf-print' ); ?></span></label><br />
497 <label><input type="checkbox" name="pdfprnt_show_btn_print_search_archive" <?php if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) echo 'checked="checked"'; ?> /> <span><?php echo __( 'Print button', 'pdf-print' ); ?></span></label>
498 </td>
499 </tr>
500 <tr>
501 <th scope="row">
502 <?php _e( 'Default template setting for search and archive:', 'pdf-print' ); ?>
503 </th>
504 <td>
505 <div>
506 <label>
507 <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
508 <input type="radio" name="pdfprnt_tmpl_search" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
509 </label>
510 </div>
511 <div>
512 <label>
513 <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
514 <input type="radio" name="pdfprnt_tmpl_search" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
515 </label>
516 </div>
517 <div>
518 <label>
519 <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
520 <input type="radio" name="pdfprnt_tmpl_search" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
521 </label>
522 </div>
523 </td>
524 </tr>
525 <tr>
526 <th scope="row"></th>
527 <td>
528 <span class="pdfprnt_explanation"><?php echo __( 'In order to use PDF and Print buttons on the search page or archive page you should put the strings below into the template source code in files search.php or archives.php ', 'pdf-print' ) . ' &#60;?php if ( function_exists( \'pdfprnt_show_buttons_search_archive\' ) ) echo pdfprnt_show_buttons_search_archive(); ?&#62;'; ?></span>
529 </td>
530 </tr>
531 <tr>
532 <th scope="row">
533 <?php _e( 'Settings for shorcodes:', 'pdf-print' ); ?>
534 </th>
535 <td>
536 <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>
537 </td>
538 </tr>
539 <tr>
540 <th scope="row"><?php _e( 'Show the print window', 'pdf-print' ); ?></th>
541 <td>
542 <input type="checkbox" name="pdfprnt_show_print_window" <?php if ( 1 == $pdfprnt_options_array['show_print_window'] ) echo 'checked="checked"'; ?> />
543 </td>
544 </tr>
545 </table>
546 <div class="bws_pro_version_bloc">
547 <div class="bws_pro_version_table_bloc">
548 <div class="bws_table_bg"></div>
549 <table class="form-table bws_pro_version">
550 <tr>
551 <th scope="row"><?php _e( 'PDF files name', 'pdf-print' ); ?></th>
552 <td>
553 <label><input disabled type="radio" name="pdfprntpr_select_file_name" value="1" /> <?php _e( 'use post or page slug', 'pdf-print' ); ?></label><br />
554 <input type="radio" disabled name="pdfprntpr_select_file_name" value="0" /><input disabled type="text" name='pdfprntpr_file_name' value="mpdf" /><br />
555 <span class="pdfprnt_explanation">
556 <?php _e( 'File name cannot contain more than 195 symbols. The file name can include Latin letters, numbers and symbols "-" , "_" only.', 'pdf-print' ) ?>
557 </span>
558 </td>
559 </tr>
560 <tr>
561 <th scope="row"><?php _e( 'Do not index pdf and print pages', 'pdf-print' ); ?></th>
562 <td>
563 <input type="checkbox" name="pdfprntpr_noindex_page" />
564 </td>
565 </tr>
566 <tr valign="top">
567 <th scope="row" colspan="2">
568 * <?php _e( 'If you upgrade to Pro version all your settings will be saved.', 'pdf-print' ); ?>
569 </th>
570 </tr>
571 </table>
572 </div>
573 <div class="bws_pro_version_tooltip">
574 <div class="bws_info">
575 <?php _e( 'Unlock premium options by upgrading to a PRO version.', 'pdf-print' ); ?>
576 <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>
577 </div>
578 <div class="bws_pro_links">
579 <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">
580 <?php _e( 'Go', 'pdf-print' ); ?> <strong>PRO</strong>
581 </a>
582 </div>
583 <div class="clear"></div>
584 </div>
585 </div>
586 <input type="hidden" name="pdfprnt_form_submit" value="1" />
587 <p class="submit">
588 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
589 </p>
590 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'pdfprnt_nonce_name' ); ?>
591 </form>
592 <div class="bws-plugin-reviews">
593 <div class="bws-plugin-reviews-rate">
594 <?php _e( 'If you enjoy our plugin, please give it 5 stars on WordPress', 'pdf-print' ); ?>:
595 <a href="http://wordpress.org/support/view/plugin-reviews/pdf-print" target="_blank" title="PDF &amp; Print reviews"><?php _e( 'Rate the plugin', 'pdf-print' ); ?></a>
596 </div>
597 <div class="bws-plugin-reviews-support">
598 <?php _e( 'If there is something wrong about it, please contact us', 'pdf-print' ); ?>:
599 <a href="http://support.bestwebsoft.com">http://support.bestwebsoft.com</a>
600 </div>
601 </div>
602 <?php } elseif ( 'extra' == $_GET['action'] ) { ?>
603 <div class="bws_pro_version_bloc">
604 <div class="bws_pro_version_table_bloc">
605 <div class="bws_table_bg"></div>
606 <table class="form-table bws_pro_version">
607 <tr valign="top">
608 <td colspan="2">
609 <?php _e( 'Please choose the necessary post types (or single pages) where PDF & Print buttons will be displayed:', 'pdf-print' ); ?>
610 </td>
611 </tr>
612 <tr valign="top">
613 <td colspan="2">
614 <label>
615 <input disabled="disabled" checked="checked" id="twttrpr_jstree_url" type="checkbox" name="twttrpr_jstree_url" value="1" />
616 <?php _e( "Show URL for pages", 'pdf-print' );?>
617 </label>
618 </td>
619 </tr>
620 <tr valign="top">
621 <td colspan="2">
622 <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' ); ?>" />
623 </td>
624 </tr>
625 <tr valign="top">
626 <td colspan="2">
627 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
628 </td>
629 </tr>
630 <tr valign="top">
631 <th scope="row" colspan="2">
632 * <?php _e( 'If you upgrade to Pro version all your settings will be saved.', 'pdf-print' ); ?>
633 </th>
634 </tr>
635 </table>
636 </div>
637 <div class="bws_pro_version_tooltip">
638 <div class="bws_info">
639 <?php _e( 'Unlock premium options by upgrading to a PRO version.', 'pdf-print' ); ?>
640 <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>
641 </div>
642 <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">
643 <?php _e( 'Go', 'pdf-print' ); ?> <strong>PRO</strong>
644 </a>
645 <div class="clear"></div>
646 </div>
647 </div>
648 <?php } elseif ( 'go_pro' == $_GET['action'] ) { ?>
649 <?php if ( isset( $pro_plugin_is_activated ) && true === $pro_plugin_is_activated ) { ?>
650 <script type="text/javascript">
651 window.setTimeout( function() {
652 window.location.href = 'admin.php?page=pdf-print-pro.php';
653 }, 5000 );
654 </script>
655 <p><?php _e( "Congratulations! The PRO version of the plugin is successfully download and activated.", 'pdf-print' ); ?></p>
656 <p>
657 <?php _e( "Please, go to", 'pdf-print' ); ?> <a href="admin.php?page=pdf-print-pro.php"><?php _e( 'the setting page', 'pdf-print' ); ?></a>
658 (<?php _e( "You will be redirected automatically in 5 seconds.", 'pdf-print' ); ?>)
659 </p>
660 <?php } else { ?>
661 <form method="post" action="admin.php?page=pdf-print.php&amp;action=go_pro">
662 <p>
663 <?php _e( 'You can download and activate', 'pdf-print' ); ?>
664 <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">PRO</a>
665 <?php _e( 'version of this plugin by entering Your license key.', 'pdf-print' ); ?><br />
666 <span style="color: #888888;font-size: 10px;">
667 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'pdf-print' ); ?>
668 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a>
669 <?php _e( '(your username is the email you specify when purchasing the product).', 'pdf-print' ); ?>
670 </span>
671 </p>
672 <?php if ( isset( $bstwbsftwppdtplgns_options['go_pro']['pdf-print-pro/pdf-print-pro.php']['count'] ) &&
673 '5' < $bstwbsftwppdtplgns_options['go_pro']['pdf-print-pro/pdf-print-pro.php']['count'] &&
674 $bstwbsftwppdtplgns_options['go_pro']['pdf-print-pro/pdf-print-pro.php']['time'] < ( time() + ( 24 * 60 * 60 ) ) ) { ?>
675 <p>
676 <input disabled="disabled" type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
677 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Go!', 'pdf-print' ); ?>" />
678 </p>
679 <p>
680 <?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'pdf-print' ); ?>
681 </p>
682 <?php } else { ?>
683 <p>
684 <input type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
685 <input type="hidden" name="bws_license_plugin" value="pdf-print-pro/pdf-print-pro.php" />
686 <input type="hidden" name="bws_license_submit" value="submit" />
687 <input type="submit" class="button-primary" value="<?php _e( 'Go!', 'pdf-print' ); ?>" />
688 <?php wp_nonce_field( plugin_basename(__FILE__), 'bws_license_nonce_name' ); ?>
689 </p>
690 <?php } ?>
691 </form>
692 <?php }
693 } ?>
694 </div>
695 <?php }
696 }
697
698 /* Positioning buttons in the page */
699 if( ! function_exists( 'pdfprnt_content' ) ) {
700 function pdfprnt_content( $content ) {
701 if ( is_admin() )
702 return;
703
704 global $pdfprnt_options_array, $post;
705 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) // Check for existence the type of posts.
706 return $content;
707 if ( 1 == $pdfprnt_options_array['show_btn_pdf'] || 1 == $pdfprnt_options_array['show_btn_print'] ) {
708 $position = ( 'top-left' == $pdfprnt_options_array['position'] || 'top-right' == $pdfprnt_options_array['position'] ) ? true : false;
709 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position'] . '">';
710 if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) {
711 if ( ! is_front_page () )
712 $permalink = add_query_arg( 'print' , 'pdf' , get_permalink( $post->ID ) );
713 else
714 $permalink = add_query_arg( 'print' , 'pdf' , get_permalink() . '?page_id=' . $post->ID );
715 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="View PDF" /></a>';
716 }
717 if ( 1 == $pdfprnt_options_array['show_btn_print'] ) {
718 if ( ! is_front_page () )
719 $permalink = add_query_arg( 'print' , 'print' , get_permalink( $post->ID ) );
720 else
721 $permalink = add_query_arg( 'print' , 'print' , get_permalink() . '?page_id=' . $post->ID );
722 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
723 }
724 $str .= '</div>';
725 if ( $position )
726 $content = $str . $content;
727 else
728 $content = $content . $str;
729 unset( $position );
730 unset( $str );
731 }
732 return $content;
733 }
734 }
735
736 /* Output buttons for search or archive pages */
737 if( ! function_exists( 'pdfprnt_show_buttons_search_archive' ) ) {
738 function pdfprnt_show_buttons_search_archive() {
739 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp, $posts;
740 if ( 0 < $pdfprnt_output_count_buttons )
741 return;
742 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_search_archive'] && 1 !== $pdfprnt_options_array['show_btn_print_search_archive'] )
743 return;
744 if ( ( ! is_search() && ! is_archive() ) || ( is_category() || ! have_posts() ) )
745 return;
746 /* Check for existence the type of posts. */
747 $is_return = true;
748 foreach ( $posts as $post ) {
749 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
750 $is_return = false;
751 break;
752 }
753 }
754 if ( $is_return )
755 return;
756 $pdfprnt_output_count_buttons++;
757 if ( empty( $wp->request ) )
758 $current_url = add_query_arg( $wp->query_string, '', home_url() );
759 else
760 $current_url = home_url( $wp->request );
761 $str = '<div class="' . $pdfprnt_options_array['position_search_archive'] . '">';
762 if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) {
763 $permalink = add_query_arg( 'print' , 'pdf-page' , $current_url );
764 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
765 }
766 if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) {
767 $permalink = add_query_arg( 'print' , 'print-page' , $current_url );
768 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
769 }
770 $str .= '</div>';
771 unset( $current_url );
772 unset( $permalink );
773 echo $str;
774 }
775 }
776 if ( ! function_exists( 'pdfprnt_auto_show_buttons_search_archive' ) ) {
777 function pdfprnt_auto_show_buttons_search_archive() {
778 if ( is_archive() || is_search() )
779 add_action( 'loop_start', 'pdfprnt_show_buttons_search_archive' );
780 }
781 add_action( 'wp_head', 'pdfprnt_auto_show_buttons_search_archive' );
782 }
783
784 /* Output buttons of page for BWS Portfolio plugin */
785 if( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio' ) ) {
786 function pdfprnt_show_buttons_for_bws_portfolio() {
787 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp;
788 if ( 0 < $pdfprnt_output_count_buttons )
789 return;
790 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
791 return;
792 if ( ! in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] ) )
793 return;
794 $pdfprnt_output_count_buttons++;
795 if ( empty( $wp->request ) )
796 $current_url = add_query_arg( $wp->query_string, '', home_url() );
797 else
798 $current_url = home_url( $wp->request );
799 $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
800 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
801 $permalink = add_query_arg( 'print' , 'pdf-portfolio-page' , $current_url );
802 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
803 }
804 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
805 $permalink = add_query_arg( 'print' , 'print-portfolio-page' , $current_url );
806 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
807 }
808 $str .= '</div>';
809 unset( $current_url );
810 unset( $permalink );
811 return $str;
812 }
813 }
814
815 /* Output buttons of post for BWS Portfolio plugin */
816 if ( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio_post' ) ) {
817 function pdfprnt_show_buttons_for_bws_portfolio_post() {
818 global $pdfprnt_options_array, $post;
819 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
820 return;
821 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
822 return;
823 $current_url = get_permalink();
824 $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
825 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
826 $permalink = add_query_arg( 'print' , 'pdf-portfolio' , $current_url );
827 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
828 }
829 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
830 $permalink = add_query_arg( 'print' , 'print-portfolio' , $current_url );
831 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
832 }
833 $str .= '</div>';
834 unset( $current_url );
835 unset( $permalink );
836 return $str;
837 }
838 }
839
840 /* Output buttons of page for custom post type */
841 if ( ! function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) {
842 function pdfprnt_show_buttons_for_custom_post_type( $custom_query ) {
843 global $pdfprnt_options_array, $pdfprnt_output_count_buttons;
844 if ( 0 < $pdfprnt_output_count_buttons )
845 return;
846 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
847 return;
848 if ( ! is_array( $custom_query ) && ! is_string( $custom_query ) )
849 return;
850 $custom_query = new WP_Query( $custom_query );
851 /* Check for existence the type of posts. */
852 $is_return = true;
853 foreach ( $custom_query->posts as $post ) {
854 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
855 $is_return = false;
856 break;
857 }
858 }
859 if ( $is_return )
860 return;
861 $pdfprnt_output_count_buttons++;
862 $current_url = add_query_arg( $custom_query->query, '', home_url() );
863 $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
864 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
865 $permalink = add_query_arg( 'print' , 'pdf-custom-page' , $current_url );
866 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
867 }
868 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
869 $permalink = add_query_arg( 'print' , 'print-custom-page' , $current_url );
870 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
871 }
872 $str .= '</div>';
873 unset( $current_url );
874 unset( $permalink );
875 unset( $is_return );
876 unset( $custom_query );
877 return $str;
878 }
879 }
880
881 /* Add links */
882 if ( ! function_exists( 'pdfprnt_action_links' ) ) {
883 function pdfprnt_action_links( $links, $file ) {
884 if ( ! is_network_admin() ) {
885 $base = plugin_basename( __FILE__ );
886 if ( $file == $base ) {
887 $settings_link = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
888 array_unshift( $links, $settings_link );
889 }
890 }
891 return $links;
892 }
893 }
894
895 /* Add links */
896 if ( ! function_exists( 'pdfprnt_links' ) ) {
897 function pdfprnt_links( $links, $file ) {
898 $base = plugin_basename( __FILE__ );
899 if ( $file == $base ) {
900 if ( ! is_network_admin() )
901 $links[] = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
902 $links[] = '<a href="http://wordpress.org/plugins/pdf-print/faq/" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>';
903 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'pdf-print' ) . '</a>';
904 }
905 return $links;
906 }
907 }
908
909 /* Add stylesheets */
910 if ( ! function_exists ( 'pdfprnt_admin_head' ) ) {
911 function pdfprnt_admin_head() {
912 global $wp_version;
913 if ( $wp_version < 3.8 )
914 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style_wp_before_3.8.css', __FILE__ ) );
915 else
916 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
917
918 if ( isset( $_GET['page'] ) && "pdf-print.php" == $_GET['page'] )
919 wp_enqueue_script( 'pdfprnt_script', plugins_url( 'js/script.js', __FILE__ ) );
920 }
921 }
922
923 /* Generate templates for pdf file or print */
924 if ( ! function_exists( 'pdfprnt_generate_template' ) ) {
925 function pdfprnt_generate_template( $content, $template = false, $isprint = false ) {
926 global $pdfprnt_options_array;
927 $tmpl = isset( $_GET['tmpl'] ) ? $_GET['tmpl'] : "";
928 ob_start(); /* Starting output buffering */ ?>
929 <html>
930 <head>
931 <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) : ?>
932 <link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo( 'stylesheet_url' ); ?>" media="all" />
933 <?php else: ?>
934 <link type="text/css" rel="stylesheet" href="<?php echo plugins_url( 'css/default.css', __FILE__ ); ?>" media="all" />
935 <?php endif;
936 if ( ! $template )
937 $template = $pdfprnt_options_array['tmpl_post'];
938 switch ( $template ) { /* Using template choosed on settings page */
939 case 1: /* Allign left template */ ?>
940 <style type="text/css">
941 h1, h2, h3, h4, h5, h6 {
942 text-align: left;
943 }
944 img {
945 float: right;
946 }
947 </style>
948 <?php break;
949 case 2: /* Allign center template */ ?>
950 <style type="text/css">
951 h1, h2, h3, h4, h5, h6 {
952 text-align: center;
953 }
954 img {
955 float: left;
956 }
957 </style>
958 <?php break;
959 case 3: /* Allign right template */ ?>
960 <style type="text/css">
961 h1, h2, h3, h4, h5, h6 {
962 text-align: right;
963 }
964 img {
965 float: left;
966 }
967 </style>
968 <?php break;
969 }
970 switch ( $tmpl ) { /* If got something by GET (from admin bar) */
971 case 1: /* Allign left template */ ?>
972 <style type="text/css">
973 h1, h2, h3, h4, h5, h6 {
974 text-align: left;
975 }
976 img {
977 float: right;
978 }
979 </style>
980 <?php break;
981 case 2: /* Allign center template */ ?>
982 <style type="text/css">
983 h1, h2, h3, h4, h5, h6 {
984 text-align: center;
985 }
986 img {
987 float: left;
988 }
989 </style>
990 <?php break;
991 case 3: /* Allign right template */ ?>
992 <style type="text/css">
993 h1, h2, h3, h4, h5, h6 {
994 text-align: right;
995 }
996 img {
997 float: left;
998 }
999 </style>
1000 <?php break;
1001 }
1002 if ( $isprint && 1 == $pdfprnt_options_array['show_print_window'] ) {
1003 echo '<script>window.onload = function(){ window.print(); };</script>';
1004 } ?>
1005 </head>
1006 <body>
1007 <?php echo $content; ?>
1008 </body>
1009 </html>
1010 <?php $html = ob_get_contents(); /* Getting output buffering */
1011 ob_end_clean(); /* Closing output buffering */
1012 return $html; /* Now we done with template */
1013 }
1014 }
1015
1016 if ( ! function_exists( 'pdfprnt_generate_template_for_bws_portfolio' ) ) {
1017 function pdfprnt_generate_template_for_bws_portfolio() {
1018 global $post;
1019 ob_start(); /* Starting output buffering */
1020 $portfolio_options = get_option( 'prtfl_options' );
1021 $meta_values = get_post_custom( $post->ID );
1022 $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
1023 if ( empty ( $post_thumbnail_id ) ) {
1024 $args = array(
1025 'post_parent' => $post->ID,
1026 'post_type' => 'attachment',
1027 'post_mime_type' => 'image',
1028 'numberposts' => 1
1029 );
1030 $attachments = get_children( $args );
1031 $post_thumbnail_id = key( $attachments );
1032 }
1033 $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
1034 $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
1035 $image_desc = get_post( $post_thumbnail_id );
1036 $image_desc = $image_desc->post_content;
1037 if ( '1' == get_option( 'prtfl_postmeta_update' ) ) {
1038 $post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
1039 $date_compl = $post_meta['_prtfl_date_compl'];
1040 if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
1041 $date_compl = explode( '/', $date_compl );
1042 $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1] . '-' . $date_compl[0] . '-' . $date_compl[2] ) );
1043 }
1044 $link = $post_meta['_prtfl_link'];
1045 $short_descr = $post_meta['_prtfl_short_descr'];
1046 } else {
1047 $date_compl = get_post_meta( $post->ID, '_prtfl_date_compl', true );
1048 if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
1049 $date_compl = explode( '/', $date_compl );
1050 $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1] . '-' . $date_compl[0] . '-' . $date_compl[2] ) );
1051 }
1052 $link = get_post_meta( $post->ID, '_prtfl_link', true);
1053 $short_descr = $post_meta['_prtfl_short_descr'];
1054 } ?>
1055 <img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" alt="<?php echo $image_alt; ?>" />
1056 <div>
1057 <p>
1058 <strong><?php _e( 'Date of completion', 'pdf-print' ); ?>:</strong> <?php echo $date_compl; ?><br/>
1059 <strong><?php _e( 'Link', 'pdf-print' ); ?>:</strong> <a href="<?php echo $link; ?>"><?php echo $link; ?></a><br/>
1060 <strong><?php _e( 'Description', 'pdf-print' ); ?>:</strong> <?php echo $short_descr; ?><br/>
1061 </p>
1062 </div>
1063 <?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
1064 if ( is_array( $terms ) && count( $terms ) > 0 ) { ?>
1065 <div style="clear:both;">
1066 <strong><?php _e( 'Technologies', 'pdf-print' ); ?>: </strong>
1067 <?php $count = 0;
1068 foreach ( $terms as $term ) {
1069 if( 0 < $count )
1070 echo ', ';
1071 echo '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
1072 $count++;
1073 } ?>
1074 </div>
1075 <?php }
1076 $content = ob_get_contents(); /* Getting output buffering */
1077 ob_end_clean(); /* Closing output buffering */
1078 return $content; /* Now we done with template */
1079 }
1080 }
1081
1082 /* Generate query posts for Portfolio plugin */
1083 if ( ! function_exists( 'generate_query_posts_for_portfolio' ) ) {
1084 function generate_query_posts_for_portfolio() {
1085 global $wp_query;
1086 $paged = isset( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 1;
1087 $technologies = isset( $wp_query->query_vars["technologies"] ) ? $wp_query->query_vars["technologies"] : "";
1088 if ( "" != $technologies ) {
1089 $args = array(
1090 'post_type' => 'portfolio',
1091 'post_status' => 'publish',
1092 'posts_per_page' => get_option('posts_per_page'),
1093 'paged' => $paged,
1094 'tax_query' => array(
1095 array(
1096 'taxonomy' => 'portfolio_technologies',
1097 'field' => 'slug',
1098 'terms' => $technologies
1099 )
1100 )
1101 );
1102 } else {
1103 $args = array(
1104 'post_type' => 'portfolio',
1105 'post_status' => 'publish',
1106 'posts_per_page' => get_option('posts_per_page'),
1107 'paged' => $paged
1108 );
1109 }
1110 query_posts( $args );
1111 }
1112 }
1113
1114 /* Output print page or pdf document and include plugin script */
1115 if ( ! function_exists( 'pdfprnt_print' ) ) {
1116 function pdfprnt_print( $query ) {
1117 global $pdfprnt_options_array, $posts, $post;
1118 if ( $print = get_query_var( 'print' ) ) {
1119 remove_all_filters( 'the_content' );
1120 add_filter( 'the_content', 'capital_P_dangit', 11 );
1121 add_filter( 'the_content', 'wptexturize' );
1122 add_filter( 'the_content', 'convert_smilies' );
1123 add_filter( 'the_content', 'convert_chars' );
1124 add_filter( 'the_content', 'wpautop' );
1125 if ( 1 == $pdfprnt_options_array['tmpl_shorcode'] ) {
1126 add_filter( 'the_content', 'do_shortcode' ); /* executing shorcodes on the page */
1127 } else {
1128 $pattern = get_shortcode_regex();
1129 if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) ) { /* getting all shortcodes we are using */
1130 foreach ( array_unique( $matches[0] ) as $value) {
1131 $post->post_content = str_replace( $value, "", $post->post_content ); /* replacing shorcodes to an empty string */
1132 }
1133 }
1134 }
1135 switch ( $print ) {
1136 case 'pdf': /* Content for PDF from post */
1137 include ( 'mpdf/mpdf.php' );
1138 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1139 $mpdf = new mPDF('+aCJK');
1140 $user_info = get_userdata( $post->post_author );
1141 $mpdf->SetAutoFont(AUTOFONT_ALL);
1142 $mpdf->SetAuthor( $user_info->display_name );
1143 $mpdf->SetTitle( $post->post_title );
1144 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1145 $html = '<div class="container">
1146 <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
1147 <div class="content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
1148 </div>';
1149 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
1150 $mpdf->Output();
1151 unset( $user_info );
1152 unset( $html );
1153 unset( $mpdf );
1154 die();
1155 break;
1156 case 'print': /* Content for printing from post */
1157 $html = '<div class="container">
1158 <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
1159 <div class="content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
1160 </div>';
1161 echo pdfprnt_generate_template( $html, false, true );
1162 unset( $html );
1163 die();
1164 break;
1165 case 'pdf-page': /* Content for PDF from archive or searching page */
1166 $html = '';
1167 $titles = array();
1168 $authors = array();
1169 include ( 'mpdf/mpdf.php' );
1170 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1171 $mpdf = new mPDF('+aCJK');
1172 foreach ( $posts as $p ) {
1173 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1174 continue;
1175 $titles[] = $p->post_title;
1176 $user_info = get_userdata( $p->post_author );
1177 $authors[] = $user_info->display_name;
1178 $html .= '<div class="container">
1179 <div class="title"><h1><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>
1180 <div class="content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
1181 </div><br/><hr/><br/>';
1182 unset( $user_info );
1183 }
1184 $titles = array_unique( $titles );
1185 $authors = array_unique( $authors );
1186 $mpdf->SetAutoFont(AUTOFONT_ALL);
1187 $mpdf->SetTitle( implode( ',', $titles ) );
1188 $mpdf->SetAuthor( implode( ',', $authors ) );
1189 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1190 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_search'] ) );
1191 $mpdf->Output();
1192 unset( $authors );
1193 unset( $titles );
1194 unset( $html );
1195 unset( $mpdf );
1196 die();
1197 break;
1198 case 'print-page': /* Content for printing from archive or searching page */
1199 $html = '';
1200 foreach ( $posts as $p ) {
1201 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1202 continue;
1203 $html .= '<div class="container">
1204 <div class="title"><h1>' . $p->post_title . '</h1></div><br/>
1205 <div class="content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
1206 </div><br/><hr/><br/>';
1207 }
1208 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_search'], true );
1209 unset( $html );
1210 die();
1211 break;
1212 case 'pdf-portfolio': /* Content for PDF from portfolio post */
1213 include ( 'mpdf/mpdf.php' );
1214 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1215 $mpdf = new mPDF( '+aCJK' );
1216 $user_info = get_userdata( $post->post_author );
1217 $mpdf->SetAutoFont( AUTOFONT_ALL );
1218 $mpdf->SetAuthor( $user_info->display_name );
1219 $mpdf->SetTitle( $post->post_title );
1220 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1221 $html = '<div class="container">
1222 <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
1223 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1224 </div>';
1225 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
1226 $mpdf->Output();
1227 unset( $html );
1228 unset( $user_info );
1229 unset( $mpdf );
1230 die();
1231 break;
1232 case 'print-portfolio': /* Content for printing from porfolio post */
1233 $html = '<div class="container">
1234 <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
1235 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1236 </div>';
1237 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
1238 unset( $html );
1239 die();
1240 break;
1241 case 'pdf-portfolio-page': /* Content for PDF from portfolio page */
1242 $html = '';
1243 $titles = array();
1244 $authors = array();
1245 generate_query_posts_for_portfolio();
1246 while ( have_posts() ) {
1247 the_post();
1248 global $post;
1249 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
1250 continue;
1251 $titles[] = $post->post_title;
1252 $user_info = get_userdata( $post->post_author );
1253 $authors[] = $user_info->display_name;
1254 $html .= '<div class="container">
1255 <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
1256 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1257 </div><br/><hr/><br/>';
1258 unset( $user_info );
1259 }
1260 include ( 'mpdf/mpdf.php' );
1261 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1262 $mpdf = new mPDF( '+aCJK' );
1263 $titles = array_unique( $titles );
1264 $authors = array_unique( $authors );
1265 $mpdf->SetAutoFont( AUTOFONT_ALL );
1266 $mpdf->SetTitle( implode( ',', $titles ) );
1267 $mpdf->SetAuthor( implode( ',', $authors ) );
1268 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1269 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
1270 $mpdf->Output();
1271 unset( $authors );
1272 unset( $titles );
1273 unset( $html );
1274 unset( $mpdf );
1275 die();
1276 break;
1277 case 'print-portfolio-page': /* Content for printing from portfolio page */
1278 generate_query_posts_for_portfolio();
1279 $html = '';
1280 while ( have_posts() ) {
1281 the_post();
1282 global $post;
1283 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
1284 continue;
1285 $html .= '<div class="container">
1286 <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
1287 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1288 </div><br/><hr/><br/>';
1289 }
1290 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
1291 unset( $html );
1292 die();
1293 break;
1294 case 'pdf-custom-page': /* Content for PDF from custom post */
1295 $html = '';
1296 $titles = $authors = array();
1297 foreach ( $posts as $p ) {
1298 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1299 continue;
1300 $titles[] = $p->post_title;
1301 $user_info = get_userdata( $p->post_author );
1302 $authors[] = $user_info->display_name;
1303 $html .= '<div class="container">';
1304 $html .= '<div class="title"><h1><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>';
1305 $html .= '<div class="content">';
1306 if ( has_post_thumbnail( $p->ID ) )
1307 $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );
1308 $html .= apply_filters( 'the_content', $p->post_content ) . '</div></div><br/><hr/><br/>';
1309 unset( $user_info );
1310 }
1311 include ( 'mpdf/mpdf.php' );
1312 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1313 $mpdf = new mPDF( '+aCJK' );
1314 $titles = array_unique( $titles );
1315 $authors = array_unique( $authors );
1316 $mpdf->SetAutoFont( AUTOFONT_ALL );
1317 $mpdf->SetTitle( implode( ',', $titles ) );
1318 $mpdf->SetAuthor( implode( ',', $authors ) );
1319 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1320 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
1321 $mpdf->Output();
1322 unset( $authors );
1323 unset( $titles );
1324 unset( $html );
1325 unset( $mpdf );
1326 die();
1327 break;
1328 case 'print-custom-page': /* Content for printing from custom post */
1329 $html = '';
1330 foreach ( $posts as $p ) {
1331 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1332 continue;
1333 $html .= '<div class="container">';
1334 $html .= '<div class="title"><h1>' . $p->post_title . '</h1></div><br/>';
1335 $html .= '<div class="content">';
1336 if ( has_post_thumbnail( $p->ID ) )
1337 $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );
1338 $html .= apply_filters( 'the_content', $p->post_content ) . '</div>
1339 </div><br/><hr/><br/>';
1340 }
1341 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
1342 unset( $html );
1343 die();
1344 break;
1345 }
1346 }
1347 }
1348 }
1349
1350 /* Add query vars */
1351 if ( ! function_exists( 'print_vars_callback' ) ) {
1352 function print_vars_callback( $query_vars ) {
1353 $query_vars[] = 'print';
1354 $query_vars[] = 'tmpl';
1355 return $query_vars;
1356 }
1357 }
1358
1359 /* Add custom admin bar menu */
1360 if ( ! function_exists( 'pdfprnt_admin_bar_menu' ) ) {
1361 function pdfprnt_admin_bar_menu() {
1362 global $pdfprnt_options_array, $wp_admin_bar, $wp, $posts;
1363 if ( ! is_super_admin() || ! is_admin_bar_showing() || is_admin() ) /* Checking user */
1364 return;
1365 if ( ( ! is_search() && ! is_archive() ) || ( is_category() || ! have_posts() ) )
1366 return;
1367 $is_return = true;
1368 foreach ( $posts as $post ) {
1369 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
1370 $is_return = false;
1371 break;
1372 }
1373 }
1374 if ( $is_return )
1375 return;
1376 if ( empty( $wp->request ) )
1377 $current_url = add_query_arg( $wp->query_string, '', home_url() );
1378 else
1379 $current_url = home_url( $wp->request );
1380 $permalink = add_query_arg( 'print', 'pdf-page', $current_url );
1381 $wp_admin_bar->add_menu( array(
1382 'id' => 'pdfprnt-bar-menu',
1383 'title' => '<span class="admin-bar-menu-bws-icon"></span>PDF',
1384 'href' => $permalink
1385 ) );
1386 $template_url = add_query_arg( 'tmpl', '1', $permalink ); /* Adding parametrs to link */
1387 $wp_admin_bar->add_menu( array(
1388 'parent' => 'pdfprnt-bar-menu',
1389 'id' => 'pdfprnt-template-1',
1390 'title' => '<img src="' . plugins_url( 'images/template_left.jpg', __FILE__ ) . '" alt="template_left" />',
1391 'href' => $template_url
1392 ) );
1393 $template_url = add_query_arg( 'tmpl', '2', $permalink ); /* Adding parametrs to link */
1394 $wp_admin_bar->add_menu( array(
1395 'parent' => 'pdfprnt-bar-menu',
1396 'id' => 'pdfprnt-template-2',
1397 'title' => '<img src="' . plugins_url( 'images/template_center.jpg', __FILE__ ) . '" alt="template_center" />',
1398 'href' => $template_url
1399 ) );
1400 $template_url = add_query_arg( 'tmpl', '3', $permalink ); /* Adding parametrs to link */
1401 $wp_admin_bar->add_menu( array(
1402 'parent' => 'pdfprnt-bar-menu',
1403 'id' => 'pdfprnt-template-3',
1404 'title' => '<img src="' . plugins_url( 'images/template_right.jpg', __FILE__ ) . '" alt="template_right" />',
1405 'href' => $template_url
1406 ) );
1407 unset( $current_url );
1408 unset( $permalink );
1409 unset( $template_url );
1410 }
1411 }
1412
1413 if ( ! function_exists ( 'pdfprnt_plugin_banner' ) ) {
1414 function pdfprnt_plugin_banner() {
1415 global $hook_suffix, $pdfprnt_plugin_info;
1416 if ( 'plugins.php' == $hook_suffix ) {
1417 $banner_array = array(
1418 array( 'sbscrbr_hide_banner_on_plugin_page', 'subscriber/subscriber.php', '1.1.8' ),
1419 array( 'lmtttmpts_hide_banner_on_plugin_page', 'limit-attempts/limit-attempts.php', '1.0.2' ),
1420 array( 'sndr_hide_banner_on_plugin_page', 'sender/sender.php', '0.5' ),
1421 array( 'srrl_hide_banner_on_plugin_page', 'user-role/user-role.php', '1.4' ),
1422 array( 'pdtr_hide_banner_on_plugin_page', 'updater/updater.php', '1.12' ),
1423 array( 'cntctfrmtdb_hide_banner_on_plugin_page', 'contact-form-to-db/contact_form_to_db.php', '1.2' ),
1424 array( 'cntctfrmmlt_hide_banner_on_plugin_page', 'contact-form-multi/contact-form-multi.php', '1.0.7' ),
1425 array( 'gglmps_hide_banner_on_plugin_page', 'bws-google-maps/bws-google-maps.php', '1.2' ),
1426 array( 'fcbkbttn_hide_banner_on_plugin_page', 'facebook-button-plugin/facebook-button-plugin.php', '2.29' ),
1427 array( 'twttr_hide_banner_on_plugin_page', 'twitter-plugin/twitter.php', '2.34' ),
1428 array( 'pdfprnt_hide_banner_on_plugin_page', 'pdf-print/pdf-print.php', '1.7.1' ),
1429 array( 'gglplsn_hide_banner_on_plugin_page', 'google-one/google-plus-one.php', '1.1.4' ),
1430 array( 'gglstmp_hide_banner_on_plugin_page', 'google-sitemap-plugin/google-sitemap-plugin.php', '2.8.4' ),
1431 array( 'cntctfrmpr_for_ctfrmtdb_hide_banner_on_plugin_page', 'contact-form-pro/contact_form_pro.php', '1.14' ),
1432 array( 'cntctfrm_for_ctfrmtdb_hide_banner_on_plugin_page', 'contact-form-plugin/contact_form.php', '3.62' ),
1433 array( 'cntctfrm_hide_banner_on_plugin_page', 'contact-form-plugin/contact_form.php', '3.47' ),
1434 array( 'cptch_hide_banner_on_plugin_page', 'captcha/captcha.php', '3.8.4' ),
1435 array( 'gllr_hide_banner_on_plugin_page', 'gallery-plugin/gallery-plugin.php', '3.9.1' )
1436 );
1437 if ( ! $pdfprnt_plugin_info )
1438 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
1439
1440 $all_plugins = get_plugins();
1441 $this_banner = 'pdfprnt_hide_banner_on_plugin_page';
1442 foreach ( $banner_array as $key => $value ) {
1443 if ( $this_banner == $value[0] ) {
1444 global $wp_version, $bstwbsftwppdtplgns_cookie_add;
1445 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
1446 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
1447 $bstwbsftwppdtplgns_cookie_add = true;
1448 } ?>
1449 <script type="text/javascript">
1450 (function($) {
1451 $(document).ready( function() {
1452 var hide_message = $.cookie( "pdfprnt_hide_banner_on_plugin_page" );
1453 if ( hide_message == "true") {
1454 $( ".pdfprnt_message" ).css( "display", "none" );
1455 } else {
1456 $( ".pdfprnt_message" ).css( "display", "block" );
1457 };
1458 $( ".pdfprnt_close_icon" ).click( function() {
1459 $( ".pdfprnt_message" ).css( "display", "none" );
1460 $.cookie( "pdfprnt_hide_banner_on_plugin_page", "true", { expires: 32 } );
1461 });
1462 });
1463 })(jQuery);
1464 </script>
1465 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
1466 <div class="pdfprnt_message bws_banner_on_plugin_page" style="display: none;">
1467 <img class="pdfprnt_close_icon close_icon" title="" src="<?php echo plugins_url( 'images/close_banner.png', __FILE__ ); ?>" alt=""/>
1468 <div class="button_div">
1469 <a class="button" target="_blank" href="http://bestwebsoft.com/products/pdf-print/?k=e2f2549f4d70bc4cb9b48071169d264e&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>"><?php _e( "Learn More", 'pdf-print' ); ?></a>
1470 </div>
1471 <div class="text">
1472 <?php _e( "It's time to upgrade your <strong>PDF & Print</strong> to <strong>PRO</strong> version", 'pdf-print' ); ?>!<br />
1473 <span><?php _e( 'Extend standard plugin functionality with new great options', 'pdf-print' ); ?>.</span>
1474 </div>
1475 <div class="icon">
1476 <img title="" src="<?php echo plugins_url( 'images/banner.png', __FILE__ ); ?>" alt=""/>
1477 </div>
1478 </div>
1479 </div>
1480 <?php break;
1481 }
1482 if ( isset( $all_plugins[ $value[1] ] ) && $all_plugins[ $value[1] ]["Version"] >= $value[2] && is_plugin_active( $value[1] ) && ! isset( $_COOKIE[ $value[0] ] ) ) {
1483 break;
1484 }
1485 }
1486 }
1487 }
1488 }
1489
1490 /* Deleting plugin options on uninstalling */
1491 if ( ! function_exists( 'pdfprnt_uninstall' ) ) {
1492 function pdfprnt_uninstall() {
1493 delete_option( 'pdfprnt_options_array' );
1494 }
1495 }
1496
1497 /* Adding function to output PDF document or pirnt page */
1498 add_action( 'wp', 'pdfprnt_print' );
1499 /* Initialization */
1500 add_action( 'init', 'pdfprnt_init' );
1501 add_action( 'admin_init', 'pdfprnt_admin_init' );
1502 /* Adding stylesheets */
1503 add_action( 'admin_enqueue_scripts', 'pdfprnt_admin_head' );
1504 add_action( 'wp_enqueue_scripts', 'pdfprnt_admin_head' );
1505 /* Adding 'BWS Plugins' admin menu */
1506 add_action( 'admin_menu', 'pdfprnt_add_pages' );
1507 /* Add menu to bar menu WordPress */
1508 add_action( 'admin_bar_menu', 'pdfprnt_admin_bar_menu', 1000 );
1509 /* Add query vars */
1510 add_filter( 'query_vars', 'print_vars_callback' );
1511 /* Additional links on the plugin page */
1512 add_filter( 'plugin_action_links', 'pdfprnt_action_links', 10, 2 );
1513 add_filter( 'plugin_row_meta', 'pdfprnt_links', 10, 2 );
1514 /* Adding buttons plugin to content */
1515 add_filter( 'the_content', 'pdfprnt_content' );
1516 /* Adding banner */
1517 add_action( 'admin_notices', 'pdfprnt_plugin_banner' );
1518 /* Plugin uninstall function */
1519 register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' );
1520 ?>
1521