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

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

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