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

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

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