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

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