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

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