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

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

1,216 lines 54.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: PDF & Print by BestWebSoft
4 Plugin URI: http://bestwebsoft.com/products/
5 Description: Plugin adds PDF creation and Print button on your site.
6 Author: BestWebSoft
7 Version: 1.8.0
8 Author URI: http://bestwebsoft.com/
9 License: GPLv2 or later
10 */
11
12 /* © Copyright 2015 BestWebSoft ( http://support.bestwebsoft.com )
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /* Add our own menu */
29 if ( ! function_exists( 'pdfprnt_add_pages' ) ) {
30 function pdfprnt_add_pages() {
31 bws_add_general_menu( plugin_basename( __FILE__ ) );
32 add_submenu_page( 'bws_plugins', __( 'PDF & Print Settings', 'pdf-print' ), 'PDF & Print', 'manage_options', 'pdf-print.php', 'pdfprnt_settings_page' );
33 }
34 }
35
36 /* Init plugin */
37 if ( ! function_exists ( 'pdfprnt_init' ) ) {
38 function pdfprnt_init() {
39 global $pdfprnt_plugin_info;
40 /* Internationalization, first(!) */
41 load_plugin_textdomain( 'pdf-print', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
42
43 require_once( dirname( __FILE__ ) . '/bws_menu/bws_functions.php' );
44
45 if ( empty( $pdfprnt_plugin_info ) ) {
46 if ( ! function_exists( 'get_plugin_data' ) ) {
47 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
48 }
49 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
50 }
51
52 /* check WordPress version */
53 bws_wp_version_check( plugin_basename( __FILE__ ), $pdfprnt_plugin_info, "3.0" );
54
55 /* Get/Register and check settings for plugin */
56 if ( ! is_admin() || ( isset( $_GET['page'] ) && 'pdf-print.php' == $_GET['page'] ) )
57 pdfprnt_settings();
58 }
59 }
60
61 if ( ! function_exists( 'pdfprnt_admin_init' ) ) {
62 function pdfprnt_admin_init() {
63 global $bws_plugin_info, $pdfprnt_plugin_info;
64
65 if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
66 $bws_plugin_info = array( 'id' => '101', 'version' => $pdfprnt_plugin_info["Version"] );
67 }
68 }
69
70 /* Register settings for plugin */
71 if ( ! function_exists( 'pdfprnt_settings' ) ) {
72 function pdfprnt_settings() {
73 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $pdfprnt_plugin_info;
74
75 if ( ! $pdfprnt_plugin_info ) {
76 if ( ! function_exists( 'get_plugin_data' ) )
77 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
78 $pdfprnt_plugin_info = get_plugin_data( __FILE__ );
79 }
80
81 /* Variable to verify performance number of once function. */
82 $pdfprnt_output_count_buttons = 0;
83 $pdfprnt_default_post_types = array();
84 /* Default post types of WordPress. */
85 foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1, '_builtin' => true ), 'names' ) as $value )
86 $pdfprnt_default_post_types[] = $value;
87
88 $pdfprnt_options_array_defaults = array(
89 'plugin_option_version' => $pdfprnt_plugin_info["Version"],
90 'position' => 'top-right',
91 'position_search_archive' => 'pdfprnt-left',
92 'position_custom' => 'pdfprnt-left',
93 'show_btn_print' => 1,
94 'show_btn_pdf' => 1,
95 'show_btn_print_search_archive' => 1,
96 'show_btn_pdf_search_archive' => 1,
97 'show_btn_print_custom' => 1,
98 'show_btn_pdf_custom' => 1,
99 'use_theme_stylesheet' => 0,
100 'tmpl_post' => 1,
101 'tmpl_search' => 1,
102 'tmpl_custom' => 1,
103 'tmpl_shorcode' => 1,
104 'use_types_posts' => $pdfprnt_default_post_types,
105 'show_print_window' => 0
106 );
107
108 if ( ! get_option( 'pdfprnt_options_array' ) )
109 add_option( 'pdfprnt_options_array', $pdfprnt_options_array_defaults );
110
111 $pdfprnt_options_array = get_option( 'pdfprnt_options_array' );
112
113 if ( ! isset( $pdfprnt_options_array['plugin_option_version'] ) || $pdfprnt_options_array['plugin_option_version'] != $pdfprnt_plugin_info["Version"] ) {
114 $pdfprnt_options_array = array_merge( $pdfprnt_options_array_defaults, $pdfprnt_options_array );
115 $pdfprnt_options_array['plugin_option_version'] = $pdfprnt_plugin_info["Version"];
116 update_option( 'pdfprnt_options_array', $pdfprnt_options_array );
117 }
118 }
119 }
120
121 /* Add admin page */
122 if ( ! function_exists ( 'pdfprnt_settings_page' ) ) {
123 function pdfprnt_settings_page () {
124 global $pdfprnt_options_array, $wp_version, $pdfprnt_plugin_info, $bstwbsftwppdtplgns_options;
125 $message = $error = "";
126 $plugin_basename = plugin_basename( __FILE__ );
127 $pdfprnt_positions_values = array(
128 'top-left' => __( 'Top Left', 'pdf-print' ),
129 'top-right' => __( 'Top Right', 'pdf-print' ),
130 'bottom-left' => __( 'Bottom Left', 'pdf-print' ),
131 'bottom-right' => __( 'Bottom Right', 'pdf-print' )
132 );
133
134 if ( ! function_exists( 'get_plugins' ) )
135 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
136 $all_plugins = get_plugins();
137
138 if ( isset( $_REQUEST['pdfprnt_position'] ) &&
139 isset( $_REQUEST['pdfprnt_position_search_archive'] ) &&
140 isset( $_REQUEST['pdfprnt_position_custom'] ) &&
141 isset( $_REQUEST['pdfprnt_use_theme_stylesheet'] ) &&
142 isset( $_REQUEST['pdfprnt_tmpl_post'] ) &&
143 isset( $_REQUEST['pdfprnt_tmpl_custom'] ) &&
144 isset( $_REQUEST['pdfprnt_tmpl_search'] ) &&
145 check_admin_referer( $plugin_basename, 'pdfprnt_nonce_name' ) ) {
146 $pdfprnt_options_array['position'] = $_REQUEST['pdfprnt_position'];
147 $pdfprnt_options_array['position_search_archive'] = $_REQUEST['pdfprnt_position_search_archive'];
148 $pdfprnt_options_array['position_custom'] = $_REQUEST['pdfprnt_position_custom'];
149 $pdfprnt_options_array['tmpl_post'] = $_REQUEST['pdfprnt_tmpl_post'];
150 $pdfprnt_options_array['tmpl_search'] = $_REQUEST['pdfprnt_tmpl_search'];
151 $pdfprnt_options_array['tmpl_custom'] = $_REQUEST['pdfprnt_tmpl_custom'];
152 $pdfprnt_options_array['use_theme_stylesheet'] = $_REQUEST['pdfprnt_use_theme_stylesheet'];
153 $pdfprnt_options_array['show_btn_pdf'] = isset( $_REQUEST['pdfprnt_show_btn_pdf'] ) ? 1 : 0;
154 $pdfprnt_options_array['show_btn_print'] = isset( $_REQUEST['pdfprnt_show_btn_print'] ) ? 1 : 0;
155 $pdfprnt_options_array['show_btn_pdf_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_search_archive'] ) ? 1 : 0;
156 $pdfprnt_options_array['show_btn_print_search_archive'] = isset( $_REQUEST['pdfprnt_show_btn_print_search_archive'] ) ? 1 : 0;
157 $pdfprnt_options_array['show_btn_pdf_custom'] = isset( $_REQUEST['pdfprnt_show_btn_pdf_custom'] ) ? 1 : 0;
158 $pdfprnt_options_array['show_btn_print_custom'] = isset( $_REQUEST['pdfprnt_show_btn_print_custom'] ) ? 1 : 0;
159 $pdfprnt_options_array['tmpl_shorcode'] = isset( $_REQUEST['pdfprnt_tmpl_shorcode'] ) ? 1 : 0;
160 $pdfprnt_options_array['show_print_window'] = isset( $_REQUEST['pdfprnt_show_print_window'] ) ? 1 : 0;
161 $pdfprnt_options_array['use_types_posts'] = isset( $_REQUEST['pdfprnt_use_types_posts'] ) ? $_REQUEST['pdfprnt_use_types_posts'] : array();
162 update_option ( 'pdfprnt_options_array', $pdfprnt_options_array );
163 $message = __( 'Settings saved.', 'pdf-print' );
164 }
165 /* GO PRO */
166 if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
167 $go_pro_result = bws_go_pro_tab_check( $plugin_basename );
168 if ( ! empty( $go_pro_result['error'] ) )
169 $error = $go_pro_result['error'];
170 } ?>
171 <div class="wrap">
172 <div class="icon32 icon32-bws" id="icon-options-general"></div>
173 <h2><?php _e( 'PDF & Print Settings', 'pdf-print' ); ?></h2>
174 <h2 class="nav-tab-wrapper">
175 <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>
176 <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>
177 <a class="nav-tab" href="http://bestwebsoft.com/products/pdf-print/faq/" target="_blank"><?php _e( 'FAQ', 'pdf-print' ); ?></a>
178 <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>
179 </h2>
180 <div class="updated fade" <?php if ( empty( $message ) || "" != $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
181 <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>
182 <div class="error" <?php if ( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
183 <?php if ( ! isset( $_GET['action'] ) ) { ?>
184 <form method="post" action="admin.php?page=pdf-print.php" id="pdfprnt_settings_form">
185 <table class="form-table pdfprnt_settings_table">
186 <tr>
187 <th scope="row"><?php _e( 'Use of theme stylesheet or plugin default style:', 'pdf-print' ); ?></th>
188 <td>
189 <select name="pdfprnt_use_theme_stylesheet">
190 <option value="0" <?php if ( 0 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Default stylesheet', 'pdf-print' ); ?></option>
191 <option value="1" <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) echo 'selected="selected"'; ?>><?php echo __( 'Current theme stylesheet', 'pdf-print' ); ?></option>
192 </select>
193 </td>
194 </tr>
195 <tr>
196 <th scope="row"><?php _e( 'The types of posts that the plugin will use:', 'pdf-print' ); ?></th>
197 <td>
198 <select name="pdfprnt_use_types_posts[]" multiple="multiple">
199 <?php foreach ( get_post_types( array( 'public' => 1, 'show_ui' => 1 ), 'objects' ) as $key => $value ) : ?>
200 <option value="<?php echo $key; ?>" <?php if ( in_array( $key, $pdfprnt_options_array['use_types_posts'] ) ) echo 'selected="selected"'; ?>><?php echo $value->label; ?></option>
201 <?php endforeach; ?>
202 </select>
203 </td>
204 </tr>
205 <?php if ( is_plugin_active( 'portfolio/portfolio.php' ) || is_plugin_active( 'portfolio-pro/portfolio-pro.php' ) ) { ?>
206 <tr>
207 <th scope="row"></th>
208 <td>
209 <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>
210 </td>
211 </tr>
212 <?php } ?>
213 <tr>
214 <th scope="row">
215 <?php _e( 'Position of buttons in content:', 'pdf-print' ); ?>
216 </th>
217 <td>
218 <select name="pdfprnt_position">
219 <?php foreach ( $pdfprnt_positions_values as $key => $value ) { ?>
220 <option value="<?php echo $key; ?>" <?php if ( $pdfprnt_options_array['position'] == $key ) echo 'selected="selected"'; ?>><?php echo $value; ?></option>
221 <?php } ?>
222 </select>
223 </td>
224 </tr>
225 <tr>
226 <th scope="row"><?php _e( 'Show:', 'pdf-print' ); ?></th>
227 <td>
228 <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 />
229 <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>
230 </td>
231 </tr>
232 <tr>
233 <th scope="row">
234 <?php _e( 'Default template setting for post:', 'pdf-print' ); ?>
235 </th>
236 <td>
237 <div>
238 <label>
239 <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
240 <input type="radio" name="pdfprnt_tmpl_post" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
241 </label>
242 </div>
243 <div>
244 <label>
245 <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
246 <input type="radio" name="pdfprnt_tmpl_post" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
247 </label>
248 </div>
249 <div>
250 <label>
251 <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
252 <input type="radio" name="pdfprnt_tmpl_post" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_post'] ) echo 'checked="checked"'; ?> />
253 </label>
254 </div>
255 </td>
256 </tr>
257 <tr>
258 <th scope="row">
259 <?php _e( 'Position of buttons in content for custom post:', 'pdf-print' ); ?>
260 </th>
261 <td>
262 <select name="pdfprnt_position_custom">
263 <option value="pdfprnt-left" <?php if ( 'pdfprnt-left' == $pdfprnt_options_array['position_custom'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Left', 'pdf-print' ); ?></option>
264 <option value="pdfprnt-right" <?php if ( 'pdfprnt-right' == $pdfprnt_options_array['position_custom'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Right', 'pdf-print' ); ?></option>
265 </select>
266 </td>
267 </tr>
268 <tr>
269 <th scope="row"><?php _e( 'Show for custom posts:', 'pdf-print' ); ?></th>
270 <td>
271 <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 />
272 <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>
273 </td>
274 </tr>
275 <tr>
276 <th scope="row">
277 <?php _e( 'Default template setting for custom posts:', 'pdf-print' ); ?>
278 </th>
279 <td>
280 <div>
281 <label>
282 <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
283 <input type="radio" name="pdfprnt_tmpl_custom" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
284 </label>
285 </div>
286 <div>
287 <label>
288 <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
289 <input type="radio" name="pdfprnt_tmpl_custom" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
290 </label>
291 </div>
292 <div>
293 <label>
294 <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
295 <input type="radio" name="pdfprnt_tmpl_custom" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_custom'] ) echo 'checked="checked"'; ?> />
296 </label>
297 </div>
298 </td>
299 </tr>
300 <tr>
301 <th scope="row"></th>
302 <td>
303 <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>
304 </td>
305 </tr>
306 <tr>
307 <th scope="row">
308 <?php _e( 'Position of buttons on search or archive page:', 'pdf-print' ); ?>
309 </th>
310 <td>
311 <select name="pdfprnt_position_search_archive">
312 <option value="pdfprnt-left" <?php if ( 'pdfprnt-left' == $pdfprnt_options_array['position_search_archive'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Left', 'pdf-print' ); ?></option>
313 <option value="pdfprnt-right" <?php if ( 'pdfprnt-right' == $pdfprnt_options_array['position_search_archive'] ) echo 'selected="selected"'; ?>><?php echo __( 'Align Right', 'pdf-print' ); ?></option>
314 </select>
315 </td>
316 </tr>
317 <tr>
318 <th scope="row"><?php _e( 'Show for search or archive page:', 'pdf-print' ); ?></th>
319 <td>
320 <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 />
321 <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>
322 </td>
323 </tr>
324 <tr>
325 <th scope="row">
326 <?php _e( 'Default template setting for search and archive:', 'pdf-print' ); ?>
327 </th>
328 <td>
329 <div>
330 <label>
331 <img src="<?php echo plugins_url( 'images/template_left.jpg', __FILE__ ); ?>" alt="template_left" />
332 <input type="radio" name="pdfprnt_tmpl_search" value="1" <?php if ( 1 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
333 </label>
334 </div>
335 <div>
336 <label>
337 <img src="<?php echo plugins_url( 'images/template_center.jpg', __FILE__ ); ?>" alt="template_center" />
338 <input type="radio" name="pdfprnt_tmpl_search" value="2" <?php if ( 2 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
339 </label>
340 </div>
341 <div>
342 <label>
343 <img src="<?php echo plugins_url( 'images/template_right.jpg', __FILE__ ); ?>" alt="template_right" />
344 <input type="radio" name="pdfprnt_tmpl_search" value="3" <?php if ( 3 == $pdfprnt_options_array['tmpl_search'] ) echo 'checked="checked"'; ?> />
345 </label>
346 </div>
347 </td>
348 </tr>
349 <tr>
350 <th scope="row"></th>
351 <td>
352 <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>
353 </td>
354 </tr>
355 <tr>
356 <th scope="row">
357 <?php _e( 'Settings for shorcodes:', 'pdf-print' ); ?>
358 </th>
359 <td>
360 <label><input type="checkbox" name="pdfprnt_tmpl_shorcode" <?php if ( 1 == $pdfprnt_options_array['tmpl_shorcode'] ) echo 'checked="checked"'; ?> /> <span><?php _e( 'Do!', 'pdf-print' ); ?></span></label>
361 </td>
362 </tr>
363 <tr>
364 <th scope="row"><?php _e( 'Show the print window', 'pdf-print' ); ?></th>
365 <td>
366 <input type="checkbox" name="pdfprnt_show_print_window" <?php if ( 1 == $pdfprnt_options_array['show_print_window'] ) echo 'checked="checked"'; ?> />
367 </td>
368 </tr>
369 </table>
370 <div class="bws_pro_version_bloc">
371 <div class="bws_pro_version_table_bloc">
372 <div class="bws_table_bg"></div>
373 <table class="form-table bws_pro_version">
374 <tr>
375 <th scope="row"><?php _e( 'PDF files name', 'pdf-print' ); ?></th>
376 <td>
377 <label><input disabled type="radio" name="pdfprntpr_select_file_name" value="1" /> <?php _e( 'use post or page slug', 'pdf-print' ); ?></label><br />
378 <input type="radio" disabled name="pdfprntpr_select_file_name" value="0" /><input disabled type="text" name='pdfprntpr_file_name' value="mpdf" /><br />
379 <span class="pdfprnt_explanation">
380 <?php _e( 'File name cannot contain more than 195 symbols. The file name can include Latin letters, numbers and symbols "-" , "_" only.', 'pdf-print' ) ?>
381 </span>
382 </td>
383 </tr>
384 <tr>
385 <th scope="row"><?php _e( 'Do not index pdf and print pages', 'pdf-print' ); ?></th>
386 <td>
387 <input type="checkbox" name="pdfprntpr_noindex_page" />
388 </td>
389 </tr>
390 <tr valign="top">
391 <th scope="row" colspan="2">
392 * <?php _e( 'If you upgrade to Pro version all your settings will be saved.', 'pdf-print' ); ?>
393 </th>
394 </tr>
395 </table>
396 </div>
397 <div class="bws_pro_version_tooltip">
398 <div class="bws_info">
399 <?php _e( 'Unlock premium options by upgrading to a PRO version.', 'pdf-print' ); ?>
400 <a href="http://bestwebsoft.com/products/pdf-print/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="PDF & Print Pro"><?php _e( 'Learn More', 'pdf-print' ); ?></a>
401 </div>
402 <div class="bws_pro_links">
403 <a class="bws_button" href="http://bestwebsoft.com/products/pdf-print/buy/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="PDF & Print Pro">
404 <?php _e( 'Go', 'pdf-print' ); ?> <strong>PRO</strong>
405 </a>
406 </div>
407 <div class="clear"></div>
408 </div>
409 </div>
410 <input type="hidden" name="pdfprnt_form_submit" value="1" />
411 <p class="submit">
412 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
413 </p>
414 <?php wp_nonce_field( $plugin_basename, 'pdfprnt_nonce_name' ); ?>
415 </form>
416 <?php bws_plugin_reviews_block( $pdfprnt_plugin_info['Name'], 'pdf-print' ); ?>
417 <?php } elseif ( 'extra' == $_GET['action'] ) { ?>
418 <div class="bws_pro_version_bloc">
419 <div class="bws_pro_version_table_bloc">
420 <div class="bws_table_bg"></div>
421 <table class="form-table bws_pro_version">
422 <tr valign="top">
423 <td colspan="2">
424 <?php _e( 'Please choose the necessary post types (or single pages) where PDF & Print buttons will be displayed:', 'pdf-print' ); ?>
425 </td>
426 </tr>
427 <tr valign="top">
428 <td colspan="2">
429 <label>
430 <input disabled="disabled" checked="checked" id="twttrpr_jstree_url" type="checkbox" name="twttrpr_jstree_url" value="1" />
431 <?php _e( "Show URL for pages", 'pdf-print' );?>
432 </label>
433 </td>
434 </tr>
435 <tr valign="top">
436 <td colspan="2">
437 <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' ); ?>" />
438 </td>
439 </tr>
440 <tr valign="top">
441 <td colspan="2">
442 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'pdf-print' ); ?>" />
443 </td>
444 </tr>
445 <tr valign="top">
446 <th scope="row" colspan="2">
447 * <?php _e( 'If you upgrade to Pro version all your settings will be saved.', 'pdf-print' ); ?>
448 </th>
449 </tr>
450 </table>
451 </div>
452 <div class="bws_pro_version_tooltip">
453 <div class="bws_info">
454 <?php _e( 'Unlock premium options by upgrading to a PRO version.', 'pdf-print' ); ?>
455 <a href="http://bestwebsoft.com/products/pdf-print/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="PDF & Print Pro"><?php _e( 'Learn More', 'pdf-print' ); ?></a>
456 </div>
457 <a class="bws_button" href="http://bestwebsoft.com/products/pdf-print/buy/?k=d9da7c9c2046bed8dfa38d005d4bffdb&pn=101&v=<?php echo $pdfprnt_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="PDF & Print Pro">
458 <?php _e( 'Go', 'pdf-print' ); ?> <strong>PRO</strong>
459 </a>
460 <div class="clear"></div>
461 </div>
462 </div>
463 <?php bws_plugin_reviews_block( $pdfprnt_plugin_info['Name'], 'pdf-print' ); ?>
464 <?php } elseif ( 'go_pro' == $_GET['action'] ) {
465 bws_go_pro_tab( $pdfprnt_plugin_info, $plugin_basename, 'pdf-print.php', 'pdf-print-pro.php', 'pdf-print-pro/pdf-print-pro.php', 'pdf-print', 'd9da7c9c2046bed8dfa38d005d4bffdb', '101', isset( $go_pro_result['pro_plugin_is_activated'] ) );
466 } ?>
467 </div>
468 <?php }
469 }
470
471 /* Positioning buttons in the page */
472 if( ! function_exists( 'pdfprnt_content' ) ) {
473 function pdfprnt_content( $content ) {
474 if ( is_admin() )
475 return;
476
477 global $pdfprnt_options_array, $post;
478 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) // Check for existence the type of posts.
479 return $content;
480 if ( 1 == $pdfprnt_options_array['show_btn_pdf'] || 1 == $pdfprnt_options_array['show_btn_print'] ) {
481 $position = ( 'top-left' == $pdfprnt_options_array['position'] || 'top-right' == $pdfprnt_options_array['position'] ) ? true : false;
482 $str = '<div class="pdfprnt-' . $pdfprnt_options_array['position'] . '">';
483 if ( 1 == $pdfprnt_options_array['show_btn_pdf'] ) {
484 if ( ! is_front_page () )
485 $permalink = add_query_arg( 'print' , 'pdf' , get_permalink( $post->ID ) );
486 else
487 $permalink = add_query_arg( 'print' , 'pdf' , get_permalink() . '?page_id=' . $post->ID );
488 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="View PDF" /></a>';
489 }
490 if ( 1 == $pdfprnt_options_array['show_btn_print'] ) {
491 if ( ! is_front_page () )
492 $permalink = add_query_arg( 'print' , 'print' , get_permalink( $post->ID ) );
493 else
494 $permalink = add_query_arg( 'print' , 'print' , get_permalink() . '?page_id=' . $post->ID );
495 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
496 }
497 $str .= '</div>';
498 if ( $position )
499 $content = $str . $content;
500 else
501 $content = $content . $str;
502 unset( $position );
503 unset( $str );
504 }
505 return $content;
506 }
507 }
508
509 /* Output buttons for search or archive pages */
510 if( ! function_exists( 'pdfprnt_show_buttons_search_archive' ) ) {
511 function pdfprnt_show_buttons_search_archive() {
512 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp, $posts;
513 if ( 0 < $pdfprnt_output_count_buttons )
514 return;
515 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_search_archive'] && 1 !== $pdfprnt_options_array['show_btn_print_search_archive'] )
516 return;
517 if ( ( ! is_search() && ! is_archive() ) || ( is_category() || ! have_posts() ) )
518 return;
519 /* Check for existence the type of posts. */
520 $is_return = true;
521 foreach ( $posts as $post ) {
522 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
523 $is_return = false;
524 break;
525 }
526 }
527 if ( $is_return )
528 return;
529 $pdfprnt_output_count_buttons++;
530 if ( empty( $wp->request ) )
531 $current_url = add_query_arg( $wp->query_string, '', home_url() );
532 else
533 $current_url = home_url( $wp->request );
534 $str = '<div class="' . $pdfprnt_options_array['position_search_archive'] . '">';
535 if ( 1 == $pdfprnt_options_array['show_btn_pdf_search_archive'] ) {
536 $permalink = add_query_arg( 'print' , 'pdf-page' , $current_url );
537 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
538 }
539 if ( 1 == $pdfprnt_options_array['show_btn_print_search_archive'] ) {
540 $permalink = add_query_arg( 'print' , 'print-page' , $current_url );
541 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
542 }
543 $str .= '</div>';
544 unset( $current_url );
545 unset( $permalink );
546 echo $str;
547 }
548 }
549 if ( ! function_exists( 'pdfprnt_auto_show_buttons_search_archive' ) ) {
550 function pdfprnt_auto_show_buttons_search_archive() {
551 if ( is_archive() || is_search() )
552 add_action( 'loop_start', 'pdfprnt_show_buttons_search_archive' );
553 }
554 add_action( 'wp_head', 'pdfprnt_auto_show_buttons_search_archive' );
555 }
556
557 /* Output buttons of page for BWS Portfolio plugin */
558 if( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio' ) ) {
559 function pdfprnt_show_buttons_for_bws_portfolio() {
560 global $pdfprnt_options_array, $pdfprnt_output_count_buttons, $wp;
561 if ( 0 < $pdfprnt_output_count_buttons )
562 return;
563 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
564 return;
565 if ( ! in_array( 'portfolio', $pdfprnt_options_array['use_types_posts'] ) )
566 return;
567 $pdfprnt_output_count_buttons++;
568 if ( empty( $wp->request ) )
569 $current_url = add_query_arg( $wp->query_string, '', home_url() );
570 else
571 $current_url = home_url( $wp->request );
572 $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
573 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
574 $permalink = add_query_arg( 'print' , 'pdf-portfolio-page' , $current_url );
575 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
576 }
577 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
578 $permalink = add_query_arg( 'print' , 'print-portfolio-page' , $current_url );
579 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
580 }
581 $str .= '</div>';
582 unset( $current_url );
583 unset( $permalink );
584 return $str;
585 }
586 }
587
588 /* Output buttons of post for BWS Portfolio plugin */
589 if ( ! function_exists( 'pdfprnt_show_buttons_for_bws_portfolio_post' ) ) {
590 function pdfprnt_show_buttons_for_bws_portfolio_post() {
591 global $pdfprnt_options_array, $post;
592 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
593 return;
594 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
595 return;
596 $current_url = get_permalink();
597 $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
598 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
599 $permalink = add_query_arg( 'print' , 'pdf-portfolio' , $current_url );
600 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
601 }
602 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
603 $permalink = add_query_arg( 'print' , 'print-portfolio' , $current_url );
604 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
605 }
606 $str .= '</div>';
607 unset( $current_url );
608 unset( $permalink );
609 return $str;
610 }
611 }
612
613 /* Output buttons of page for custom post type */
614 if ( ! function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) {
615 function pdfprnt_show_buttons_for_custom_post_type( $custom_query ) {
616 global $pdfprnt_options_array, $pdfprnt_output_count_buttons;
617 if ( 0 < $pdfprnt_output_count_buttons )
618 return;
619 if ( 1 !== $pdfprnt_options_array['show_btn_pdf_custom'] && 1 !== $pdfprnt_options_array['show_btn_print_custom'] )
620 return;
621 if ( ! is_array( $custom_query ) && ! is_string( $custom_query ) )
622 return;
623 $custom_query = new WP_Query( $custom_query );
624 /* Check for existence the type of posts. */
625 $is_return = true;
626 foreach ( $custom_query->posts as $post ) {
627 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
628 $is_return = false;
629 break;
630 }
631 }
632 if ( $is_return )
633 return;
634 $pdfprnt_output_count_buttons++;
635 $current_url = add_query_arg( $custom_query->query, '', home_url() );
636 $str = '<div class="' . $pdfprnt_options_array['position_custom'] . '">';
637 if ( 1 == $pdfprnt_options_array['show_btn_pdf_custom'] ) {
638 $permalink = add_query_arg( 'print' , 'pdf-custom-page' , $current_url );
639 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/pdf.png', __FILE__ ) . '" alt="image_pdf" title="Print PDF" /></a>';
640 }
641 if ( 1 == $pdfprnt_options_array['show_btn_print_custom'] ) {
642 $permalink = add_query_arg( 'print' , 'print-custom-page' , $current_url );
643 $str .= '<a href="' . $permalink . '" target="_blank"><img src="' . plugins_url( 'images/print.gif', __FILE__ ) . '" alt="image_print" title="Print Content" /></a>';
644 }
645 $str .= '</div>';
646 unset( $current_url );
647 unset( $permalink );
648 unset( $is_return );
649 unset( $custom_query );
650 return $str;
651 }
652 }
653
654 /* Add links */
655 if ( ! function_exists( 'pdfprnt_action_links' ) ) {
656 function pdfprnt_action_links( $links, $file ) {
657 if ( ! is_network_admin() ) {
658 $base = plugin_basename( __FILE__ );
659 if ( $file == $base ) {
660 $settings_link = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
661 array_unshift( $links, $settings_link );
662 }
663 }
664 return $links;
665 }
666 }
667
668 /* Add links */
669 if ( ! function_exists( 'pdfprnt_links' ) ) {
670 function pdfprnt_links( $links, $file ) {
671 $base = plugin_basename( __FILE__ );
672 if ( $file == $base ) {
673 if ( ! is_network_admin() )
674 $links[] = '<a href="admin.php?page=pdf-print.php">' . __( 'Settings', 'pdf-print' ) . '</a>';
675 $links[] = '<a href="http://wordpress.org/plugins/pdf-print/faq/" target="_blank">' . __( 'FAQ', 'pdf-print' ) . '</a>';
676 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'pdf-print' ) . '</a>';
677 }
678 return $links;
679 }
680 }
681
682 /* Add stylesheets */
683 if ( ! function_exists ( 'pdfprnt_admin_head' ) ) {
684 function pdfprnt_admin_head() {
685 global $wp_version;
686 if ( $wp_version < 3.8 )
687 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style_wp_before_3.8.css', __FILE__ ) );
688 else
689 wp_enqueue_style( 'pdfprnt_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
690
691 if ( isset( $_GET['page'] ) && "pdf-print.php" == $_GET['page'] )
692 wp_enqueue_script( 'pdfprnt_script', plugins_url( 'js/script.js', __FILE__ ) );
693 }
694 }
695
696 /* Generate templates for pdf file or print */
697 if ( ! function_exists( 'pdfprnt_generate_template' ) ) {
698 function pdfprnt_generate_template( $content, $template = false, $isprint = false ) {
699 global $pdfprnt_options_array;
700 $tmpl = isset( $_GET['tmpl'] ) ? $_GET['tmpl'] : "";
701 ob_start(); /* Starting output buffering */ ?>
702 <html>
703 <head>
704 <?php if ( 1 == $pdfprnt_options_array['use_theme_stylesheet'] ) : ?>
705 <link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo( 'stylesheet_url' ); ?>" media="all" />
706 <?php else: ?>
707 <link type="text/css" rel="stylesheet" href="<?php echo plugins_url( 'css/default.css', __FILE__ ); ?>" media="all" />
708 <?php endif;
709 if ( ! $template )
710 $template = $pdfprnt_options_array['tmpl_post'];
711 switch ( $template ) { /* Using template choosed on settings page */
712 case 1: /* Allign left template */ ?>
713 <style type="text/css">
714 h1, h2, h3, h4, h5, h6 {
715 text-align: left;
716 }
717 img {
718 float: right;
719 }
720 </style>
721 <?php break;
722 case 2: /* Allign center template */ ?>
723 <style type="text/css">
724 h1, h2, h3, h4, h5, h6 {
725 text-align: center;
726 }
727 img {
728 float: left;
729 }
730 </style>
731 <?php break;
732 case 3: /* Allign right template */ ?>
733 <style type="text/css">
734 h1, h2, h3, h4, h5, h6 {
735 text-align: right;
736 }
737 img {
738 float: left;
739 }
740 </style>
741 <?php break;
742 }
743 switch ( $tmpl ) { /* If got something by GET (from admin bar) */
744 case 1: /* Allign left template */ ?>
745 <style type="text/css">
746 h1, h2, h3, h4, h5, h6 {
747 text-align: left;
748 }
749 img {
750 float: right;
751 }
752 </style>
753 <?php break;
754 case 2: /* Allign center template */ ?>
755 <style type="text/css">
756 h1, h2, h3, h4, h5, h6 {
757 text-align: center;
758 }
759 img {
760 float: left;
761 }
762 </style>
763 <?php break;
764 case 3: /* Allign right template */ ?>
765 <style type="text/css">
766 h1, h2, h3, h4, h5, h6 {
767 text-align: right;
768 }
769 img {
770 float: left;
771 }
772 </style>
773 <?php break;
774 }
775 if ( $isprint && 1 == $pdfprnt_options_array['show_print_window'] ) {
776 echo '<script>window.onload = function(){ window.print(); };</script>';
777 } ?>
778 </head>
779 <body>
780 <?php echo $content; ?>
781 </body>
782 </html>
783 <?php $html = ob_get_contents(); /* Getting output buffering */
784 ob_end_clean(); /* Closing output buffering */
785 return $html; /* Now we done with template */
786 }
787 }
788
789 if ( ! function_exists( 'pdfprnt_generate_template_for_bws_portfolio' ) ) {
790 function pdfprnt_generate_template_for_bws_portfolio() {
791 global $post;
792 ob_start(); /* Starting output buffering */
793 $short_descr = $link = $date_compl = '';
794 $meta_values = get_post_custom( $post->ID );
795 $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
796 if ( empty ( $post_thumbnail_id ) ) {
797 $args = array(
798 'post_parent' => $post->ID,
799 'post_type' => 'attachment',
800 'post_mime_type' => 'image',
801 'numberposts' => 1
802 );
803 $attachments = get_children( $args );
804 $post_thumbnail_id = key( $attachments );
805 }
806 $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
807 $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
808 $image_desc = get_post( $post_thumbnail_id );
809 $image_desc = $image_desc->post_content;
810 $post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
811 if ( ! empty( $post_meta ) ) {
812 $date_compl = $post_meta['_prtfl_date_compl'];
813 if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
814 $date_compl = explode( '/', $date_compl );
815 $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1] . '-' . $date_compl[0] . '-' . $date_compl[2] ) );
816 }
817 $link = $post_meta['_prtfl_link'];
818 $short_descr = $post_meta['_prtfl_short_descr'];
819 } ?>
820 <img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" alt="<?php echo $image_alt; ?>" />
821 <div>
822 <p>
823 <strong><?php _e( 'Date of completion', 'pdf-print' ); ?>:</strong> <?php echo $date_compl; ?><br/>
824 <strong><?php _e( 'Link', 'pdf-print' ); ?>:</strong> <a href="<?php echo $link; ?>"><?php echo $link; ?></a><br/>
825 <strong><?php _e( 'Description', 'pdf-print' ); ?>:</strong> <?php echo $short_descr; ?><br/>
826 </p>
827 </div>
828 <?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
829 if ( is_array( $terms ) && count( $terms ) > 0 ) { ?>
830 <div style="clear:both;">
831 <strong><?php _e( 'Technologies', 'pdf-print' ); ?>: </strong>
832 <?php $count = 0;
833 foreach ( $terms as $term ) {
834 if ( 0 < $count )
835 echo ', ';
836 echo '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
837 $count++;
838 } ?>
839 </div>
840 <?php }
841 $content = ob_get_contents(); /* Getting output buffering */
842 ob_end_clean(); /* Closing output buffering */
843 return $content; /* Now we done with template */
844 }
845 }
846
847 /* Generate query posts for Portfolio plugin */
848 if ( ! function_exists( 'generate_query_posts_for_portfolio' ) ) {
849 function generate_query_posts_for_portfolio() {
850 global $wp_query;
851 $paged = isset( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 1;
852 $technologies = isset( $wp_query->query_vars["technologies"] ) ? $wp_query->query_vars["technologies"] : "";
853 if ( "" != $technologies ) {
854 $args = array(
855 'post_type' => 'portfolio',
856 'post_status' => 'publish',
857 'posts_per_page' => get_option('posts_per_page'),
858 'paged' => $paged,
859 'tax_query' => array(
860 array(
861 'taxonomy' => 'portfolio_technologies',
862 'field' => 'slug',
863 'terms' => $technologies
864 )
865 )
866 );
867 } else {
868 $args = array(
869 'post_type' => 'portfolio',
870 'post_status' => 'publish',
871 'posts_per_page' => get_option('posts_per_page'),
872 'paged' => $paged
873 );
874 }
875 query_posts( $args );
876 }
877 }
878
879 /* Output print page or pdf document and include plugin script */
880 if ( ! function_exists( 'pdfprnt_print' ) ) {
881 function pdfprnt_print( $query ) {
882 global $pdfprnt_options_array, $posts, $post;
883 if ( $print = get_query_var( 'print' ) ) {
884 remove_all_filters( 'the_content' );
885 add_filter( 'the_content', 'capital_P_dangit', 11 );
886 add_filter( 'the_content', 'wptexturize' );
887 add_filter( 'the_content', 'convert_smilies' );
888 add_filter( 'the_content', 'convert_chars' );
889 add_filter( 'the_content', 'wpautop' );
890 if ( 1 == $pdfprnt_options_array['tmpl_shorcode'] ) {
891 add_filter( 'the_content', 'do_shortcode' ); /* executing shorcodes on the page */
892 } else {
893 $pattern = get_shortcode_regex();
894 if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) ) { /* getting all shortcodes we are using */
895 foreach ( array_unique( $matches[0] ) as $value) {
896 $post->post_content = str_replace( $value, "", $post->post_content ); /* replacing shorcodes to an empty string */
897 }
898 }
899 }
900 switch ( $print ) {
901 case 'pdf': /* Content for PDF from post */
902 include ( 'mpdf/mpdf.php' );
903 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
904 $mpdf = new mPDF('+aCJK');
905 $user_info = get_userdata( $post->post_author );
906 $mpdf->SetAutoFont(AUTOFONT_ALL);
907 $mpdf->SetAuthor( $user_info->display_name );
908 $mpdf->SetTitle( $post->post_title );
909 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
910 $html = '<div class="container">
911 <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
912 <div class="content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
913 </div>';
914 $mpdf->WriteHTML( pdfprnt_generate_template( $html ) );
915 $mpdf->Output();
916 unset( $user_info );
917 unset( $html );
918 unset( $mpdf );
919 die();
920 break;
921 case 'print': /* Content for printing from post */
922 $html = '<div class="container">
923 <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
924 <div class="content">' . apply_filters( 'the_content', $post->post_content ) . '</div>
925 </div>';
926 echo pdfprnt_generate_template( $html, false, true );
927 unset( $html );
928 die();
929 break;
930 case 'pdf-page': /* Content for PDF from archive or searching page */
931 $html = '';
932 $titles = array();
933 $authors = array();
934 include ( 'mpdf/mpdf.php' );
935 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
936 $mpdf = new mPDF('+aCJK');
937 foreach ( $posts as $p ) {
938 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
939 continue;
940 $titles[] = $p->post_title;
941 $user_info = get_userdata( $p->post_author );
942 $authors[] = $user_info->display_name;
943 $html .= '<div class="container">
944 <div class="title"><h1><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>
945 <div class="content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
946 </div><br/><hr/><br/>';
947 unset( $user_info );
948 }
949 $titles = array_unique( $titles );
950 $authors = array_unique( $authors );
951 $mpdf->SetAutoFont(AUTOFONT_ALL);
952 $mpdf->SetTitle( implode( ',', $titles ) );
953 $mpdf->SetAuthor( implode( ',', $authors ) );
954 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
955 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_search'] ) );
956 $mpdf->Output();
957 unset( $authors );
958 unset( $titles );
959 unset( $html );
960 unset( $mpdf );
961 die();
962 break;
963 case 'print-page': /* Content for printing from archive or searching page */
964 $html = '';
965 foreach ( $posts as $p ) {
966 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
967 continue;
968 $html .= '<div class="container">
969 <div class="title"><h1>' . $p->post_title . '</h1></div><br/>
970 <div class="content">' . apply_filters( 'the_content', $p->post_content ) . '</div>
971 </div><br/><hr/><br/>';
972 }
973 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_search'], true );
974 unset( $html );
975 die();
976 break;
977 case 'pdf-portfolio': /* Content for PDF from portfolio post */
978 include ( 'mpdf/mpdf.php' );
979 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
980 $mpdf = new mPDF( '+aCJK' );
981 $user_info = get_userdata( $post->post_author );
982 $mpdf->SetAutoFont( AUTOFONT_ALL );
983 $mpdf->SetAuthor( $user_info->display_name );
984 $mpdf->SetTitle( $post->post_title );
985 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
986 $html = '<div class="container">
987 <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
988 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
989 </div>';
990 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
991 $mpdf->Output();
992 unset( $html );
993 unset( $user_info );
994 unset( $mpdf );
995 die();
996 break;
997 case 'print-portfolio': /* Content for printing from porfolio post */
998 $html = '<div class="container">
999 <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
1000 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1001 </div>';
1002 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
1003 unset( $html );
1004 die();
1005 break;
1006 case 'pdf-portfolio-page': /* Content for PDF from portfolio page */
1007 $html = '';
1008 $titles = array();
1009 $authors = array();
1010 generate_query_posts_for_portfolio();
1011 while ( have_posts() ) {
1012 the_post();
1013 global $post;
1014 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
1015 continue;
1016 $titles[] = $post->post_title;
1017 $user_info = get_userdata( $post->post_author );
1018 $authors[] = $user_info->display_name;
1019 $html .= '<div class="container">
1020 <div class="title"><h1><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h1></div><br/>
1021 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1022 </div><br/><hr/><br/>';
1023 unset( $user_info );
1024 }
1025 include ( 'mpdf/mpdf.php' );
1026 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1027 $mpdf = new mPDF( '+aCJK' );
1028 $titles = array_unique( $titles );
1029 $authors = array_unique( $authors );
1030 $mpdf->SetAutoFont( AUTOFONT_ALL );
1031 $mpdf->SetTitle( implode( ',', $titles ) );
1032 $mpdf->SetAuthor( implode( ',', $authors ) );
1033 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1034 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
1035 $mpdf->Output();
1036 unset( $authors );
1037 unset( $titles );
1038 unset( $html );
1039 unset( $mpdf );
1040 die();
1041 break;
1042 case 'print-portfolio-page': /* Content for printing from portfolio page */
1043 generate_query_posts_for_portfolio();
1044 $html = '';
1045 while ( have_posts() ) {
1046 the_post();
1047 global $post;
1048 if ( ! in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) )
1049 continue;
1050 $html .= '<div class="container">
1051 <div class="title"><h1>' . $post->post_title . '</h1></div><br/>
1052 <div class="content">' . pdfprnt_generate_template_for_bws_portfolio() . '</div>
1053 </div><br/><hr/><br/>';
1054 }
1055 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
1056 unset( $html );
1057 die();
1058 break;
1059 case 'pdf-custom-page': /* Content for PDF from custom post */
1060 $html = '';
1061 $titles = $authors = array();
1062 foreach ( $posts as $p ) {
1063 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1064 continue;
1065 $titles[] = $p->post_title;
1066 $user_info = get_userdata( $p->post_author );
1067 $authors[] = $user_info->display_name;
1068 $html .= '<div class="container">';
1069 $html .= '<div class="title"><h1><a href="' . get_permalink( $p->ID ) . '">' . $p->post_title . '</a></h1></div><br/>';
1070 $html .= '<div class="content">';
1071 if ( has_post_thumbnail( $p->ID ) )
1072 $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );
1073 $html .= apply_filters( 'the_content', $p->post_content ) . '</div></div><br/><hr/><br/>';
1074 unset( $user_info );
1075 }
1076 include ( 'mpdf/mpdf.php' );
1077 $mpdf = new mPDF( get_bloginfo( 'charset' ) );
1078 $mpdf = new mPDF( '+aCJK' );
1079 $titles = array_unique( $titles );
1080 $authors = array_unique( $authors );
1081 $mpdf->SetAutoFont( AUTOFONT_ALL );
1082 $mpdf->SetTitle( implode( ',', $titles ) );
1083 $mpdf->SetAuthor( implode( ',', $authors ) );
1084 $mpdf->SetSubject( get_bloginfo( 'blogdescription' ) );
1085 $mpdf->WriteHTML( pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'] ) );
1086 $mpdf->Output();
1087 unset( $authors );
1088 unset( $titles );
1089 unset( $html );
1090 unset( $mpdf );
1091 die();
1092 break;
1093 case 'print-custom-page': /* Content for printing from custom post */
1094 $html = '';
1095 foreach ( $posts as $p ) {
1096 if ( ! in_array( get_post_type( $p ), $pdfprnt_options_array['use_types_posts'] ) )
1097 continue;
1098 $html .= '<div class="container">';
1099 $html .= '<div class="title"><h1>' . $p->post_title . '</h1></div><br/>';
1100 $html .= '<div class="content">';
1101 if ( has_post_thumbnail( $p->ID ) )
1102 $html .= get_the_post_thumbnail( $p->ID, 'thumbnail' );
1103 $html .= apply_filters( 'the_content', $p->post_content ) . '</div>
1104 </div><br/><hr/><br/>';
1105 }
1106 echo pdfprnt_generate_template( $html, $pdfprnt_options_array['tmpl_custom'], true );
1107 unset( $html );
1108 die();
1109 break;
1110 }
1111 }
1112 }
1113 }
1114
1115 /* Add query vars */
1116 if ( ! function_exists( 'print_vars_callback' ) ) {
1117 function print_vars_callback( $query_vars ) {
1118 $query_vars[] = 'print';
1119 $query_vars[] = 'tmpl';
1120 return $query_vars;
1121 }
1122 }
1123
1124 /* Add custom admin bar menu */
1125 if ( ! function_exists( 'pdfprnt_admin_bar_menu' ) ) {
1126 function pdfprnt_admin_bar_menu() {
1127 global $pdfprnt_options_array, $wp_admin_bar, $wp, $posts;
1128 if ( ! is_super_admin() || ! is_admin_bar_showing() || is_admin() ) /* Checking user */
1129 return;
1130 if ( ( ! is_search() && ! is_archive() ) || ( is_category() || ! have_posts() ) )
1131 return;
1132 $is_return = true;
1133 foreach ( $posts as $post ) {
1134 if ( in_array( get_post_type( $post ), $pdfprnt_options_array['use_types_posts'] ) ) {
1135 $is_return = false;
1136 break;
1137 }
1138 }
1139 if ( $is_return )
1140 return;
1141 if ( empty( $wp->request ) )
1142 $current_url = add_query_arg( $wp->query_string, '', home_url() );
1143 else
1144 $current_url = home_url( $wp->request );
1145 $permalink = add_query_arg( 'print', 'pdf-page', $current_url );
1146 $wp_admin_bar->add_menu( array(
1147 'id' => 'pdfprnt-bar-menu',
1148 'title' => '<span class="admin-bar-menu-bws-icon"></span>PDF',
1149 'href' => $permalink
1150 ) );
1151 $template_url = add_query_arg( 'tmpl', '1', $permalink ); /* Adding parametrs to link */
1152 $wp_admin_bar->add_menu( array(
1153 'parent' => 'pdfprnt-bar-menu',
1154 'id' => 'pdfprnt-template-1',
1155 'title' => '<img src="' . plugins_url( 'images/template_left.jpg', __FILE__ ) . '" alt="template_left" />',
1156 'href' => $template_url
1157 ) );
1158 $template_url = add_query_arg( 'tmpl', '2', $permalink ); /* Adding parametrs to link */
1159 $wp_admin_bar->add_menu( array(
1160 'parent' => 'pdfprnt-bar-menu',
1161 'id' => 'pdfprnt-template-2',
1162 'title' => '<img src="' . plugins_url( 'images/template_center.jpg', __FILE__ ) . '" alt="template_center" />',
1163 'href' => $template_url
1164 ) );
1165 $template_url = add_query_arg( 'tmpl', '3', $permalink ); /* Adding parametrs to link */
1166 $wp_admin_bar->add_menu( array(
1167 'parent' => 'pdfprnt-bar-menu',
1168 'id' => 'pdfprnt-template-3',
1169 'title' => '<img src="' . plugins_url( 'images/template_right.jpg', __FILE__ ) . '" alt="template_right" />',
1170 'href' => $template_url
1171 ) );
1172 unset( $current_url );
1173 unset( $permalink );
1174 unset( $template_url );
1175 }
1176 }
1177
1178 if ( ! function_exists ( 'pdfprnt_plugin_banner' ) ) {
1179 function pdfprnt_plugin_banner() {
1180 global $hook_suffix, $pdfprnt_plugin_info;
1181 if ( 'plugins.php' == $hook_suffix ) {
1182 bws_plugin_banner( $pdfprnt_plugin_info, 'pdfprnt', 'pdf-print', 'e2f2549f4d70bc4cb9b48071169d264e', '101', '//ps.w.org/pdf-print/assets/icon-128x128.png' );
1183 }
1184 }
1185 }
1186
1187 /* Deleting plugin options on uninstalling */
1188 if ( ! function_exists( 'pdfprnt_uninstall' ) ) {
1189 function pdfprnt_uninstall() {
1190 delete_option( 'pdfprnt_options_array' );
1191 }
1192 }
1193
1194 /* Adding function to output PDF document or pirnt page */
1195 add_action( 'wp', 'pdfprnt_print' );
1196 /* Initialization */
1197 add_action( 'init', 'pdfprnt_init' );
1198 add_action( 'admin_init', 'pdfprnt_admin_init' );
1199 /* Adding stylesheets */
1200 add_action( 'admin_enqueue_scripts', 'pdfprnt_admin_head' );
1201 add_action( 'wp_enqueue_scripts', 'pdfprnt_admin_head' );
1202 /* Adding 'BWS Plugins' admin menu */
1203 add_action( 'admin_menu', 'pdfprnt_add_pages' );
1204 /* Add menu to bar menu WordPress */
1205 add_action( 'admin_bar_menu', 'pdfprnt_admin_bar_menu', 1000 );
1206 /* Add query vars */
1207 add_filter( 'query_vars', 'print_vars_callback' );
1208 /* Additional links on the plugin page */
1209 add_filter( 'plugin_action_links', 'pdfprnt_action_links', 10, 2 );
1210 add_filter( 'plugin_row_meta', 'pdfprnt_links', 10, 2 );
1211 /* Adding buttons plugin to content */
1212 add_filter( 'the_content', 'pdfprnt_content' );
1213 /* Adding banner */
1214 add_action( 'admin_notices', 'pdfprnt_plugin_banner' );
1215 /* Plugin uninstall function */
1216 register_uninstall_hook( __FILE__, 'pdfprnt_uninstall' );