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

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